|
|
@ -7,29 +7,36 @@ Project structure: |
|
|
|
├── backend |
|
|
|
├── backend |
|
|
|
│  ├── Dockerfile |
|
|
|
│  ├── Dockerfile |
|
|
|
│  ├── go.mod |
|
|
|
│  ├── go.mod |
|
|
|
|
|
|
|
│  ├── go.sum |
|
|
|
│  └── main.go |
|
|
|
│  └── main.go |
|
|
|
├── db |
|
|
|
├── db |
|
|
|
│  └── password.txt |
|
|
|
│  └── password.txt |
|
|
|
├── compose.yaml |
|
|
|
├── compose.yaml |
|
|
|
├── proxy |
|
|
|
├── proxy |
|
|
|
│  ├── conf |
|
|
|
│  └── nginx.conf |
|
|
|
│  └── Dockerfile |
|
|
|
|
|
|
|
└── README.md |
|
|
|
└── README.md |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
[_compose.yaml_](compose.yaml) |
|
|
|
[_compose.yaml_](compose.yaml) |
|
|
|
``` |
|
|
|
```shell |
|
|
|
services: |
|
|
|
services: |
|
|
|
backend: |
|
|
|
backend: |
|
|
|
build: backend |
|
|
|
build: |
|
|
|
|
|
|
|
context: backend |
|
|
|
|
|
|
|
target: builder |
|
|
|
... |
|
|
|
... |
|
|
|
db: |
|
|
|
db: |
|
|
|
image: postgres |
|
|
|
image: postgres |
|
|
|
... |
|
|
|
... |
|
|
|
proxy: |
|
|
|
proxy: |
|
|
|
build: proxy |
|
|
|
image: nginx |
|
|
|
|
|
|
|
volumes: |
|
|
|
|
|
|
|
- type: bind |
|
|
|
|
|
|
|
source: ./proxy/nginx.conf |
|
|
|
|
|
|
|
target: /etc/nginx/conf.d/default.conf |
|
|
|
|
|
|
|
read_only: true |
|
|
|
ports: |
|
|
|
ports: |
|
|
|
- 80:80 |
|
|
|
- 80:80 |
|
|
|
... |
|
|
|
... |
|
|
|
``` |
|
|
|
``` |
|
|
|
The compose file defines an application with three services `proxy`, `backend` and `db`. |
|
|
|
The compose file defines an application with three services `proxy`, `backend` and `db`. |
|
|
@ -38,7 +45,7 @@ Make sure port 80 on the host is not already being in use. |
|
|
|
|
|
|
|
|
|
|
|
## Deploy with docker compose |
|
|
|
## Deploy with docker compose |
|
|
|
|
|
|
|
|
|
|
|
``` |
|
|
|
```shell |
|
|
|
$ docker compose up -d |
|
|
|
$ docker compose up -d |
|
|
|
Creating network "nginx-golang-postgres_default" with the default driver |
|
|
|
Creating network "nginx-golang-postgres_default" with the default driver |
|
|
|
Pulling db (postgres:)... |
|
|
|
Pulling db (postgres:)... |
|
|
@ -55,21 +62,32 @@ Creating nginx-golang-postgres_proxy_1 ... done |
|
|
|
## Expected result |
|
|
|
## Expected result |
|
|
|
|
|
|
|
|
|
|
|
Listing containers must show three containers running and the port mapping as below: |
|
|
|
Listing containers must show three containers running and the port mapping as below: |
|
|
|
``` |
|
|
|
```shell |
|
|
|
$ docker ps |
|
|
|
$ docker compose ps |
|
|
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
|
|
|
NAME COMMAND SERVICE STATUS PORTS |
|
|
|
5e3ecd0289c0 nginx-golang-postgres_proxy "nginx -g 'daemon of…" 48 seconds ago Up 48 seconds 0.0.0.0:80->80/tcp nginx-golang-postgres_proxy_1 |
|
|
|
nginx-golang-postgres-backend-1 "/code/bin/backend" backend running |
|
|
|
ffa1410b1c8a nginx-golang-postgres_backend "/server" 49 seconds ago Up 48 seconds 8000/tcp nginx-golang-postgres_backend_1 |
|
|
|
nginx-golang-postgres-db-1 "docker-entrypoint.s…" db running (healthy) 5432/tcp |
|
|
|
e63be7db7cbc postgres "docker-entrypoint.s…" 49 seconds ago Up 49 seconds 5432/tcp nginx-golang-postgres_db_1 |
|
|
|
nginx-golang-postgres-proxy-1 "/docker-entrypoint.…" proxy running 0.0.0.0:80->80/tcp |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
After the application starts, navigate to `http://localhost:80` in your web browser or run: |
|
|
|
After the application starts, navigate to `http://localhost:80` in your web browser or run: |
|
|
|
``` |
|
|
|
```shell |
|
|
|
$ curl localhost:80 |
|
|
|
$ curl localhost:80 |
|
|
|
["Blog post #0","Blog post #1","Blog post #2","Blog post #3","Blog post #4"] |
|
|
|
["Blog post #0","Blog post #1","Blog post #2","Blog post #3","Blog post #4"] |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
Stop and remove the containers |
|
|
|
Stop and remove the containers |
|
|
|
``` |
|
|
|
```shell |
|
|
|
$ docker compose down |
|
|
|
$ docker compose down |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Use with Docker Development Environments |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
You can use this sample with the Dev Environments feature of Docker Desktop. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
![Screenshot of creating a Dev Environment in Docker Desktop](../dev-envs.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
To develop directly on the services inside containers, use the HTTPS Git url of the sample: |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
https://github.com/docker/awesome-compose/tree/master/nginx-golang-postgres |
|
|
|
|
|
|
|
``` |
|
|
|