diff --git a/05-example-web-application/client-react/nginx.conf b/05-example-web-application/client-react/nginx.conf index e592961..983ff45 100644 --- a/05-example-web-application/client-react/nginx.conf +++ b/05-example-web-application/client-react/nginx.conf @@ -1,5 +1,5 @@ server { - listen 80; + listen 8080; # Docker internal dns server resolver 127.0.0.11; diff --git a/06-building-container-images/client-react/Dockerfile.4 b/06-building-container-images/client-react/Dockerfile.4 index 09364d8..9c5b7dd 100644 --- a/06-building-container-images/client-react/Dockerfile.4 +++ b/06-building-container-images/client-react/Dockerfile.4 @@ -23,4 +23,4 @@ COPY nginx.conf /etc/nginx/conf.d/default.conf COPY --from=build usr/src/app/dist/ /usr/share/nginx/html -EXPOSE 80 \ No newline at end of file +EXPOSE 8080 \ No newline at end of file diff --git a/06-building-container-images/client-react/Dockerfile.5 b/06-building-container-images/client-react/Dockerfile.5 index 19310d8..ad54f5b 100644 --- a/06-building-container-images/client-react/Dockerfile.5 +++ b/06-building-container-images/client-react/Dockerfile.5 @@ -26,4 +26,4 @@ COPY --link nginx.conf /etc/nginx/conf.d/default.conf COPY --link --from=build usr/src/app/dist/ /usr/share/nginx/html -EXPOSE 80 \ No newline at end of file +EXPOSE 8080 \ No newline at end of file diff --git a/07-container-registries/Makefile b/07-container-registries/Makefile index 5d504a6..7e0500a 100644 --- a/07-container-registries/Makefile +++ b/07-container-registries/Makefile @@ -5,17 +5,17 @@ build: # Have to authenticate to dockerhub and create repo first: # https://docs.docker.com/engine/reference/commandline/login/ .PHONY: push-dockerhub -push-dockerhub: build +push-dockerhub: docker tag my-scratch-image sidpalas/my-scratch-image # defaults to latest docker push sidpalas/my-scratch-image - docker tag my-scratch-image sidpalas/my-scratch-image:abc-123 # defaults to latest + docker tag my-scratch-image sidpalas/my-scratch-image:abc-123 docker push sidpalas/my-scratch-image:abc-123 # Have to authenticate to ghcr.io first # https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-to-the-container-registry .PHONY: push-github-packages -push-github-packages: build +push-github-packages: docker tag my-scratch-image ghcr.io/sidpalas/my-scratch-image # defaults to latest docker push ghcr.io/sidpalas/my-scratch-image diff --git a/08-running-containers/Makefile b/08-running-containers/Makefile index a57bbee..190cd17 100644 --- a/08-running-containers/Makefile +++ b/08-running-containers/Makefile @@ -31,6 +31,8 @@ docker-build-all: docker build -t api-golang -f ${DOCKERFILE_DIR}/api-golang/Dockerfile.6 ${DOCKERCONTEXT_DIR}/api-golang/ +DATABASE_URL:=postgres://postgres:foobarbaz@db:5432/postgres + .PHONY: docker-run-all docker-run-all: echo "$$DOCKER_COMPOSE_NOTE" @@ -40,8 +42,11 @@ docker-run-all: $(MAKE) docker-rm + docker network create my-network + docker run -d \ --name db \ + --network my-network \ -e POSTGRES_PASSWORD=foobarbaz \ -v pgdata:/var/lib/postgresql/data \ -p 5432:5432 \ @@ -50,7 +55,8 @@ docker-run-all: docker run -d \ --name api-node \ - -e DATABASE_URL=postgres://postgres:foobarbaz@db:5432/postgres \ + --network my-network \ + -e DATABASE_URL=${DATABASE_URL} \ -p 3000:3000 \ --restart unless-stopped \ --link=db \ @@ -58,7 +64,8 @@ docker-run-all: docker run -d \ --name api-golang \ - -e DATABASE_URL=postgres://postgres:foobarbaz@db:5432/postgres \ + --network my-network \ + -e DATABASE_URL=${DATABASE_URL} \ -p 8080:8080 \ --restart unless-stopped \ --link=db \ @@ -66,6 +73,7 @@ docker-run-all: docker run -d \ --name client-react-vite \ + --network my-network \ -v ${PWD}/client-react/vite.config.js:/usr/src/app/vite.config.js \ -p 5173:5173 \ --restart unless-stopped \ @@ -75,6 +83,7 @@ docker-run-all: docker run -d \ --name client-react-nginx \ + --network my-network \ -p 5174:80 \ --restart unless-stopped \ --link=api-node \ @@ -96,6 +105,7 @@ docker-rm: -docker container rm api-golang -docker container rm client-react-vite -docker container rm client-react-nginx + -docker network rm my-network define DOCKER_COMPOSE_NOTE diff --git a/08-running-containers/docker-compose.yml b/08-running-containers/docker-compose.yml index 161aa70..2ab0609 100644 --- a/08-running-containers/docker-compose.yml +++ b/08-running-containers/docker-compose.yml @@ -1,13 +1,29 @@ services: + client-react-vite: + image: client-react-vite + build: + context: ../05-example-web-application/client-react/ + dockerfile: ../../06-building-container-images/client-react/Dockerfile.4 + init: true + volumes: + - ${PWD}/client-react/vite.config.js:/usr/src/app/vite.config.js + networks: + - frontend + ports: + - 5173:5173 client-react-nginx: + image: client-react-nginx build: context: ../05-example-web-application/client-react/ dockerfile: ../../06-building-container-images/client-react/Dockerfile.5 init: true + networks: + - frontend ports: - - 5174:80 + - 80:8080 restart: unless-stopped api-node: + image: api-node build: context: ../05-example-web-application/api-node/ dockerfile: ../../06-building-container-images/api-node/Dockerfile.8 @@ -16,10 +32,14 @@ services: - db environment: - DATABASE_URL=postgres://postgres:foobarbaz@db:5432/postgres + networks: + - frontend + - backend ports: - 3000:3000 restart: unless-stopped api-golang: + image: api-golang build: context: ../05-example-web-application/api-golang/ dockerfile: ../../06-building-container-images/api-golang/Dockerfile.6 @@ -28,6 +48,9 @@ services: - db environment: - DATABASE_URL=postgres://postgres:foobarbaz@db:5432/postgres + networks: + - frontend + - backend ports: - 8080:8080 restart: unless-stopped @@ -37,7 +60,12 @@ services: - pgdata:/var/lib/postgresql/data environment: - POSTGRES_PASSWORD=foobarbaz + networks: + - backend ports: - 5432:5432 volumes: - pgdata: \ No newline at end of file + pgdata: +networks: + frontend: + backend: \ No newline at end of file