Skip to content

Commit 9da70ed

Browse files
committed
🌈🌈🌈 Initial commit 🌈🌈🌈
0 parents  commit 9da70ed

File tree

8 files changed

+1405
-0
lines changed

8 files changed

+1405
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# docker-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 a _user-defined bridge network_, and the application container fetches 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+
## To run
8+
9+
To try out this demo, first build the images:
10+
11+
```bash
12+
docker build -t address-book app
13+
14+
docker build -t address-db db
15+
```
16+
17+
Then create a bridge network, and run the containers:
18+
19+
```bash
20+
docker network create address-app
21+
22+
docker run -d --name address-db --network address-app address-db:latest
23+
24+
docker run -d --name address-book --network address-app address-book:latest
25+
```
26+
27+
Now you can test the application from another container; we'll use an Alpine Linux container for this:
28+
29+
```bash
30+
docker run -it --rm --network address-app alpine:latest
31+
```
32+
33+
Then inside the Alpine container, install the **curl** command, and use it to test the API:
34+
35+
```bash
36+
apk add --no-cache curl
37+
curl address-book:3000/addresses
38+
```
39+
40+
You should see output like this, which proves that the application container has successfully fetched data from the database container:
41+
42+
```json
43+
[{"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"}]
44+
```
45+
46+
## Cleanup
47+
48+
```bash
49+
$ docker stop address-book address-db
50+
$ docker rm address-book address-db
51+
$ docker network rm address-app
52+
```
53+
54+
## License
55+
56+
MIT

app/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM docker.io/library/node:18
2+
3+
WORKDIR /app
4+
5+
COPY package.json .
6+
7+
RUN npm install
8+
9+
COPY . .
10+
11+
CMD ["node", "server.js"]

0 commit comments

Comments
 (0)