awesome-compose/nginx-flask-mongo
Atomist Bot f06bab3ff4 Pin Docker image python:3.10-alpine
--platform=$BUILDPLATFORM
->
python:3.10-alpine@sha256:c9d3c11e89887c82efeb4f4fee8771a406cf42f41aebbd23148906d5fe3c1426

 [atomist:generated]
 [atomist-skill:atomist/docker-base-image-policy]

Signed-off-by: Atomist Bot <bot@atomist.com>
2022-10-07 07:12:40 +00:00
..
.docker nginx-flask-mongo: add dev envs support (#268) 2022-07-12 11:31:52 +02:00
flask Pin Docker image python:3.10-alpine 2022-10-07 07:12:40 +00:00
nginx Move all samples to the root dir 2020-03-16 17:23:59 +01:00
compose.yaml nginx-flask-mongo: add dev envs support (#268) 2022-07-12 11:31:52 +02:00
README.md Add "Open in Docker Dev Environments" links (#280) 2022-09-01 11:39:33 -05:00

Compose sample application

Use with Docker Development Environments

You can open this sample in the Dev Environments feature of Docker Desktop version 4.12 or later.

Open in Docker Dev Environments Open in Docker Dev Environments

Python/Flask application with Nginx proxy and a Mongo database

Project structure:

.
├── compose.yaml
├── flask
│   ├── Dockerfile
│   ├── requirements.txt
│   └── server.py
└── nginx
    └── nginx.conf

compose.yaml

services:
  web:
    build: app
    ports:
    - 80:80
  backend:
    build: flask
    ...
  mongo:
    image: mongo

The compose file defines an application with three services web, backend and db. When deploying the application, docker compose maps port 80 of the web service container to port 80 of the host as specified in the file. Make sure port 80 on the host is not being used by another container, otherwise the port should be changed.

Deploy with docker compose

$ docker compose up -d
Creating network "nginx-flask-mongo_default" with the default driver
Pulling mongo (mongo:)...
latest: Pulling from library/mongo
423ae2b273f4: Pull complete
...
...
Status: Downloaded newer image for nginx:latest
Creating nginx-flask-mongo_mongo_1 ... done
Creating nginx-flask-mongo_backend_1 ... done
Creating nginx-flask-mongo_web_1     ... done

Expected result

Listing containers must show three containers running and the port mapping as below:

$ docker ps
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                  NAMES
a0f4ebe686ff        nginx                       "/bin/bash -c 'envsu…"   About a minute ago   Up About a minute   0.0.0.0:80->80/tcp     nginx-flask-mongo_web_1
dba87a080821        nginx-flask-mongo_backend   "./server.py"            About a minute ago   Up About a minute                          nginx-flask-mongo_backend_1
d7eea5481c77        mongo                       "docker-entrypoint.s…"   About a minute ago   Up About a minute   27017/tcp              nginx-flask-mongo_mongo_1

After the application starts, navigate to http://localhost:80 in your web browser or run:

$ curl localhost:80
Hello from the MongoDB client!

Stop and remove the containers

$ docker compose down