Skip to content

Commit 7010a74

Browse files
committed
use custom network for docker run commands
1 parent c954a82 commit 7010a74

6 files changed

Lines changed: 48 additions & 10 deletions

File tree

‎05-example-web-application/client-react/nginx.conf‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
server {
2-
listen 80;
2+
listen 8080;
33

44
# Docker internal dns server
55
resolver 127.0.0.11;

‎06-building-container-images/client-react/Dockerfile.4‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ COPY nginx.conf /etc/nginx/conf.d/default.conf
2323

2424
COPY --from=build usr/src/app/dist/ /usr/share/nginx/html
2525

26-
EXPOSE 80
26+
EXPOSE 8080

‎06-building-container-images/client-react/Dockerfile.5‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ COPY --link nginx.conf /etc/nginx/conf.d/default.conf
2626

2727
COPY --link --from=build usr/src/app/dist/ /usr/share/nginx/html
2828

29-
EXPOSE 80
29+
EXPOSE 8080

‎07-container-registries/Makefile‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ build:
55
# Have to authenticate to dockerhub and create repo first:
66
# https://docs.docker.com/engine/reference/commandline/login/
77
.PHONY: push-dockerhub
8-
push-dockerhub: build
8+
push-dockerhub:
99
docker tag my-scratch-image sidpalas/my-scratch-image # defaults to latest
1010
docker push sidpalas/my-scratch-image
1111

12-
docker tag my-scratch-image sidpalas/my-scratch-image:abc-123 # defaults to latest
12+
docker tag my-scratch-image sidpalas/my-scratch-image:abc-123
1313
docker push sidpalas/my-scratch-image:abc-123
1414

1515
# Have to authenticate to ghcr.io first
1616
# https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-to-the-container-registry
1717
.PHONY: push-github-packages
18-
push-github-packages: build
18+
push-github-packages:
1919
docker tag my-scratch-image ghcr.io/sidpalas/my-scratch-image # defaults to latest
2020
docker push ghcr.io/sidpalas/my-scratch-image
2121

‎08-running-containers/Makefile‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ docker-build-all:
3131

3232
docker build -t api-golang -f ${DOCKERFILE_DIR}/api-golang/Dockerfile.6 ${DOCKERCONTEXT_DIR}/api-golang/
3333

34+
DATABASE_URL:=postgres://postgres:foobarbaz@db:5432/postgres
35+
3436
.PHONY: docker-run-all
3537
docker-run-all:
3638
echo "$$DOCKER_COMPOSE_NOTE"
@@ -40,8 +42,11 @@ docker-run-all:
4042

4143
$(MAKE) docker-rm
4244

45+
docker network create my-network
46+
4347
docker run -d \
4448
--name db \
49+
--network my-network \
4550
-e POSTGRES_PASSWORD=foobarbaz \
4651
-v pgdata:/var/lib/postgresql/data \
4752
-p 5432:5432 \
@@ -50,22 +55,25 @@ docker-run-all:
5055

5156
docker run -d \
5257
--name api-node \
53-
-e DATABASE_URL=postgres://postgres:foobarbaz@db:5432/postgres \
58+
--network my-network \
59+
-e DATABASE_URL=${DATABASE_URL} \
5460
-p 3000:3000 \
5561
--restart unless-stopped \
5662
--link=db \
5763
api-node
5864

5965
docker run -d \
6066
--name api-golang \
61-
-e DATABASE_URL=postgres://postgres:foobarbaz@db:5432/postgres \
67+
--network my-network \
68+
-e DATABASE_URL=${DATABASE_URL} \
6269
-p 8080:8080 \
6370
--restart unless-stopped \
6471
--link=db \
6572
api-golang
6673

6774
docker run -d \
6875
--name client-react-vite \
76+
--network my-network \
6977
-v ${PWD}/client-react/vite.config.js:/usr/src/app/vite.config.js \
7078
-p 5173:5173 \
7179
--restart unless-stopped \
@@ -75,6 +83,7 @@ docker-run-all:
7583

7684
docker run -d \
7785
--name client-react-nginx \
86+
--network my-network \
7887
-p 5174:80 \
7988
--restart unless-stopped \
8089
--link=api-node \
@@ -96,6 +105,7 @@ docker-rm:
96105
-docker container rm api-golang
97106
-docker container rm client-react-vite
98107
-docker container rm client-react-nginx
108+
-docker network rm my-network
99109

100110
define DOCKER_COMPOSE_NOTE
101111

‎08-running-containers/docker-compose.yml‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
services:
2+
client-react-vite:
3+
image: client-react-vite
4+
build:
5+
context: ../05-example-web-application/client-react/
6+
dockerfile: ../../06-building-container-images/client-react/Dockerfile.4
7+
init: true
8+
volumes:
9+
- ${PWD}/client-react/vite.config.js:/usr/src/app/vite.config.js
10+
networks:
11+
- frontend
12+
ports:
13+
- 5173:5173
214
client-react-nginx:
15+
image: client-react-nginx
316
build:
417
context: ../05-example-web-application/client-react/
518
dockerfile: ../../06-building-container-images/client-react/Dockerfile.5
619
init: true
20+
networks:
21+
- frontend
722
ports:
8-
- 5174:80
23+
- 80:8080
924
restart: unless-stopped
1025
api-node:
26+
image: api-node
1127
build:
1228
context: ../05-example-web-application/api-node/
1329
dockerfile: ../../06-building-container-images/api-node/Dockerfile.8
@@ -16,10 +32,14 @@ services:
1632
- db
1733
environment:
1834
- DATABASE_URL=postgres://postgres:foobarbaz@db:5432/postgres
35+
networks:
36+
- frontend
37+
- backend
1938
ports:
2039
- 3000:3000
2140
restart: unless-stopped
2241
api-golang:
42+
image: api-golang
2343
build:
2444
context: ../05-example-web-application/api-golang/
2545
dockerfile: ../../06-building-container-images/api-golang/Dockerfile.6
@@ -28,6 +48,9 @@ services:
2848
- db
2949
environment:
3050
- DATABASE_URL=postgres://postgres:foobarbaz@db:5432/postgres
51+
networks:
52+
- frontend
53+
- backend
3154
ports:
3255
- 8080:8080
3356
restart: unless-stopped
@@ -37,7 +60,12 @@ services:
3760
- pgdata:/var/lib/postgresql/data
3861
environment:
3962
- POSTGRES_PASSWORD=foobarbaz
63+
networks:
64+
- backend
4065
ports:
4166
- 5432:5432
4267
volumes:
43-
pgdata:
68+
pgdata:
69+
networks:
70+
frontend:
71+
backend:

0 commit comments

Comments
 (0)