11## Compose sample application
2- ### Go server with an Nginx proxy and a MySQL database
2+ ### Go server with an Nginx proxy and a MariaDB/ MySQL database
33
44Project structure:
55```
66.
77├── backend
88│ ├── Dockerfile
99│ ├── go.mod
10+ │ ├── go.sum
1011│ └── main.go
1112├── db
1213│ └── password.txt
13- ├── compose.yaml
1414├── proxy
15- │ ├ ── conf
16- │ └ ── Dockerfile
15+ │ └ ── nginx. conf
16+ ├ ── compose.yaml
1717└── README.md
1818```
1919
2020[ _ compose.yaml_ ] ( compose.yaml )
21- ```
21+ ``` yaml
2222services :
2323 backend :
24- build: backend
24+ build :
25+ context : backend
26+ target : builder
2527 ...
2628 db :
2729 # We use a mariadb image which supports both amd64 & arm64 architecture
28- image: mariadb:10.6.4 -focal
30+ image : mariadb:10-focal
2931 # If you really want to use MySQL, uncomment the following line
30- #image: mysql:8.0.27
32+ # image: mysql:8
3133 ...
3234 proxy :
33- build: proxy
35+ image : nginx
36+ volumes :
37+ - type : bind
38+ source : ./proxy/nginx.conf
39+ target : /etc/nginx/conf.d/default.conf
40+ read_only : true
3441 ports :
3542 - 80:80
3643 ...
@@ -42,11 +49,11 @@ Make sure port 80 on the host is not already being in use.
4249> ℹ️ ** _ INFO_ **
4350> For compatibility purpose between ` AMD64 ` and ` ARM64 ` architecture, we use a MariaDB as database instead of MySQL.
4451> You still can use the MySQL image by uncommenting the following line in the Compose file
45- > ` #image: mysql:8.0.27 `
52+ > ` #image: mysql:8 `
4653
4754## Deploy with docker compose
4855
49- ```
56+ ``` shell
5057$ docker compose up -d
5158Creating network " nginx-golang-mysql_default" with the default driver
5259Building backend
@@ -64,24 +71,33 @@ Creating nginx-golang-mysql_proxy_1 ... done
6471## Expected result
6572
6673Listing containers must show three containers running and the port mapping as below:
67- ```
68- $ docker ps
69- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
70- 8906b14c5ad1 nginx-golang-mysql_proxy "nginx -g 'daemon of…" 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp nginx-golang-mysq
71- l_proxy_1
72- 13e0e0a7715a nginx-golang-mysql_backend "/server" 2 minutes ago Up 2 minutes 8000/tcp nginx-golang-mysq
73- l_backend_1
74- ca8c5975d205 mysql:5.7 "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 3306/tcp, 33060/tcp nginx-golang-mysq
74+ ``` shell
75+ $ docker compose ps
76+ NAME COMMAND SERVICE STATUS PORTS
77+ nginx-golang-mysql-backend-1 " /code/bin/backend" backend running
78+ nginx-golang-mysql-db-1 " docker-entrypoint.s…" db running (healthy) 3306/tcp
79+ nginx-golang-mysql-proxy-1 " /docker-entrypoint.…" proxy running 0.0.0.0:80-> 80/tcp
7580l_db_1
7681```
7782
7883After the application starts, navigate to ` http://localhost:80 ` in your web browser or run:
79- ```
84+ ``` shell
8085$ curl localhost:80
8186[" Blog post #0" ," Blog post #1" ," Blog post #2" ," Blog post #3" ," Blog post #4" ]
8287```
8388
8489Stop and remove the containers
85- ```
90+ ``` shell
8691$ docker compose down
8792```
93+
94+ ## Use with Docker Development Environments
95+
96+ You can use this sample with the Dev Environments feature of Docker Desktop.
97+
98+ ![ Screenshot of creating a Dev Environment in Docker Desktop] ( ../dev-envs.png )
99+
100+ To develop directly on the services inside containers, use the HTTPS Git url of the sample:
101+ ```
102+ https://github.com/docker/awesome-compose/tree/master/nginx-golang-mysql
103+ ```
0 commit comments