nginx-flask-mysql: add dev envs support (#272)

* Add Docker Desktop Development Environments config
* Change port `5000` -> `8000` for Flask to avoid conflicts on
  recent macOS versions
* Improve DB health check (for non-dev envs case) to avoid
  producing a bunch of log spam

Co-authored-by: Guillaume Lours <guillaume@lours.me>
Signed-off-by: Milas Bowman <milas.bowman@docker.com>
This commit is contained in:
Milas Bowman
2022-07-13 08:44:29 -04:00
committed by GitHub
parent 20089c790b
commit 111c55d56b
5 changed files with 130 additions and 24 deletions

View File

@@ -18,13 +18,15 @@ Project structure:
```
services:
backend:
build: backend
build:
context: backend
target: builder
...
db:
# We use a mariadb image which supports both amd64 & arm64 architecture
image: mariadb:10.6.4-focal
image: mariadb:10-focal
# If you really want to use MySQL, uncomment the following line
#image: mysql:8.0.27
#image: mysql:8
...
proxy:
build: proxy
@@ -37,7 +39,7 @@ Make sure port 80 on the host is not already being in use.
> **_INFO_**
> For compatibility purpose between `AMD64` and `ARM64` architecture, we use a MariaDB as database instead of MySQL.
> You still can use the MySQL image by uncommenting the following line in the Compose file
> `#image: mysql:8.0.27`
> `#image: mysql:8`
## Deploy with docker compose
@@ -56,15 +58,13 @@ Creating nginx-flask-mysql_proxy_1 ... done
## Expected result
Listing containers must show three containers running and the port mapping as below:
Listing containers should show three containers running and the port mapping as below:
```
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c2c703b66b19 nginx-flask-mysql_proxy "nginx -g 'daemon of…" 39 seconds ago Up 38 seconds 0.0.0.0:80->80/tcp nginx-flask-mysql_proxy_1
2b8a21508c3c nginx-flask-mysql_backend "/bin/sh -c 'flask r…" 9 minutes ago Up 38 seconds 0.0.0.0:5000->5000/tcp nginx-flask-mysql_backend_1
0e6a96ea2028 mysql:8.0.19 "docker-entrypoint.s…" 9 minutes ago Up 38 seconds 3306/tcp, 33060/tcp nginx-flask-mysql_db_1
$ docker compose ps
NAME COMMAND SERVICE STATUS PORTS
nginx-flask-mysql-backend-1 "flask run" backend running 0.0.0.0:8000->8000/tcp
nginx-flask-mysql-db-1 "docker-entrypoint.s…" db running (healthy) 3306/tcp, 33060/tcp
nginx-flask-mysql-proxy-1 "nginx -g 'daemon of…" proxy running 0.0.0.0:80->80/tcp
```
After the application starts, navigate to `http://localhost:80` in your web browser or run:
@@ -77,3 +77,14 @@ Stop and remove the containers
```
$ 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-flask-mysql
```