Skip to content

Commit 64c84f2

Browse files
committed
Move networking to subdir
1 parent 6e9098e commit 64c84f2

File tree

10 files changed

+78
-72
lines changed

10 files changed

+78
-72
lines changed

README.md

Lines changed: 3 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,6 @@
1-
# container-network-demo
1+
# container-demos
22

3-
**A demo of joining two Docker containers to a network.** This demo involves two containers, one for an application and one for a database. Both containers are joined to the same [user-defined bridge network][bridge], so that the application container can fetch data from the database.
3+
A repository of demos for fun and interesting things to try with containers!
44

5-
The application itself is a simple Node.js application that uses the [Express](https://expressjs.com/) framework. It exposes a REST API at `localhost:8080/addresses` that fetches a list of addresses from the Postgresql database.
5+
**This is a work-in-progress!** Explore the directory structure to find the demos.
66

7-
The database is populated with a few sample addresses in the file `db/init.sql`. Feel free to add your own addresses to the database before running the instructions below, and see if they show up in the API response!
8-
9-
## Architecture
10-
11-
This diagram shows the architecture of this demo - an application and a database, and a third container for testing, all joined to the same bridge network.
12-
13-
<img src="./architecture.png">
14-
15-
## To run
16-
17-
**Pre-requisites:** You must have Docker installed on your machine.
18-
19-
To try out this demo, first build the images:
20-
21-
```bash
22-
docker build -t address-api app
23-
24-
docker build -t address-db db
25-
```
26-
27-
Then create a bridge network, and run the containers:
28-
29-
```bash
30-
docker network create address-app
31-
32-
docker run -d --name address-db --network address-app address-db:latest
33-
34-
docker run -d --name address-api --network address-app address-api:latest
35-
```
36-
37-
Now you can test the application from another container; we'll use an [Alpine Linux][alpine] container for this:
38-
39-
```bash
40-
docker run -it --rm --network address-app alpine:latest
41-
```
42-
43-
Then, **inside the Alpine container,** install the **curl** command, and use it to test the API:
44-
45-
```bash
46-
apk add --no-cache curl
47-
48-
curl address-api:3000/addresses
49-
```
50-
51-
You should see output like this, which proves that the application container has successfully fetched data from the database container:
52-
53-
```json
54-
[{"id":1,"first_name":"John","last_name":"Doe","email":"john@example.com","phone":"555-555-5555"},{"id":2,"first_name":"Jane","last_name":"Doe","email":"jane@example.com","phone":"555-555-5557"},{"id":3,"first_name":"Susan","last_name":"Smith","email":"susan@example.com","phone":"555-555-5558"},{"id":4,"first_name":"Bob","last_name":"Smith","email":"bob@example.com","phone":"555-555-5559"}]
55-
```
56-
57-
## Cleanup
58-
59-
To stop and remove the containers, and remove the network:
60-
61-
```bash
62-
docker stop address-api address-db
63-
64-
docker rm address-api address-db
65-
66-
docker network rm address-app
67-
```
68-
69-
## License
70-
71-
[MIT][license]
72-
73-
[alpine]: https://alpinelinux.org/
74-
[bridge]: https://docs.docker.com/network/bridge/
75-
[license]: LICENSE
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# container-network-demo
2+
3+
**A demo of joining two Docker containers to a network.** This demo involves two containers, one for an application and one for a database. Both containers are joined to the same [user-defined bridge network][bridge], so that the application container can fetch data from the database.
4+
5+
The application itself is a simple Node.js application that uses the [Express](https://expressjs.com/) framework. It exposes a REST API at `localhost:8080/addresses` that fetches a list of addresses from the Postgresql database.
6+
7+
The database is populated with a few sample addresses in the file `db/init.sql`. Feel free to add your own addresses to the database before running the instructions below, and see if they show up in the API response!
8+
9+
## Architecture
10+
11+
This diagram shows the architecture of this demo - an application and a database, and a third container for testing, all joined to the same bridge network.
12+
13+
<img src="./architecture.png">
14+
15+
## To run
16+
17+
**Pre-requisites:** You must have Docker installed on your machine.
18+
19+
To try out this demo, first build the images:
20+
21+
```bash
22+
docker build -t address-api app
23+
24+
docker build -t address-db db
25+
```
26+
27+
Then create a bridge network, and run the containers:
28+
29+
```bash
30+
docker network create address-app
31+
32+
docker run -d --name address-db --network address-app address-db:latest
33+
34+
docker run -d --name address-api --network address-app address-api:latest
35+
```
36+
37+
Now you can test the application from another container; we'll use an [Alpine Linux][alpine] container for this:
38+
39+
```bash
40+
docker run -it --rm --network address-app alpine:latest
41+
```
42+
43+
Then, **inside the Alpine container,** install the **curl** command, and use it to test the API:
44+
45+
```bash
46+
apk add --no-cache curl
47+
48+
curl address-api:3000/addresses
49+
```
50+
51+
You should see output like this, which proves that the application container has successfully fetched data from the database container:
52+
53+
```json
54+
[{"id":1,"first_name":"John","last_name":"Doe","email":"john@example.com","phone":"555-555-5555"},{"id":2,"first_name":"Jane","last_name":"Doe","email":"jane@example.com","phone":"555-555-5557"},{"id":3,"first_name":"Susan","last_name":"Smith","email":"susan@example.com","phone":"555-555-5558"},{"id":4,"first_name":"Bob","last_name":"Smith","email":"bob@example.com","phone":"555-555-5559"}]
55+
```
56+
57+
## Cleanup
58+
59+
To stop and remove the containers, and remove the network:
60+
61+
```bash
62+
docker stop address-api address-db
63+
64+
docker rm address-api address-db
65+
66+
docker network rm address-app
67+
```
68+
69+
## License
70+
71+
[MIT][license]
72+
73+
[alpine]: https://alpinelinux.org/
74+
[bridge]: https://docs.docker.com/network/bridge/
75+
[license]: LICENSE

app/package-lock.json renamed to networking/bridge-network/app/package-lock.json

File renamed without changes.

app/package.json renamed to networking/bridge-network/app/package.json

File renamed without changes.

architecture.png renamed to networking/bridge-network/architecture.png

File renamed without changes.

docker-compose.yaml renamed to networking/bridge-network/docker-compose.yaml

File renamed without changes.

0 commit comments

Comments
 (0)