Step 2: Setup the docker-compose
environment
The goal for Step 2: Create a docker-compose.yml
file with a defined
volume for your Flask Quotes application.
Note
We’ll use port 20854 for the reverse proxy.
Table of Contents
2.1. Create the docker-compose.yml
file and add support files
Create a folder for your Flask Quotes application called
flask-quotes
and create an emptydocker-compose.yml
file.cd ~ mkdir flask-quotes cd flask-quotes touch docker-compose.yml
Verify the information in the
Dockerfile
.Before you create your
docker-compose.yml
file, you will need information from yourDockerfile
. Open it to verify that nothing has changed.WORKDIR /app ----> For the volume (where code files are) EXPOSE 5000 ----> For port mapping (the port that that the Python web server is running on)
Write the
docker-compose.yml
file to usepython/flask:dev
and with defined a volume calledquotes-app
or something similar Here is your template (fill in the data from yourDockerfile
):- Destination volume
The working directory (
WORKDIR
) defined in the image- Destination port
The port (
EXPOSE
) that the Python web server runs onTip
EXPOSE
is a best-practice marker only. The actual port is defined in theindex.py
fileapp.run(host="0.0.0.0", port=int("5000"), debug=True)
version: '3' services: flask: image: python/flask:dev volumes: - ./quotes-app:/_____ ports: - 20854:____ restart: always
Now, can create the
volume
with theindex.py
to create a basichellow world
Flask app, as a first-step for all new projects. 🧑💻🙂# All code files will go here mkdir quotes-app # copy the index.py file that you put inside of python/flask:dev cp ~/flask-dev-image/index.py quotes-app/ # Your directory should look like this: sysadmin@test2:~/flask-quotes$ tree . ├── docker-compose.yml └── quotes-app └── index.py 1 directory, 2 files
Verify the config, start the container, and verify that it returns the expected result:
sysadmin@test2:~/flask-quotes$ sysadmin@test2:~/flask-quotes$ docker-compose config services: flask: image: python/flask:dev ports: - 20854:5000/tcp restart: always volumes: - /home/sysadmin/flask-working/flask-quotes/app:/app:rw version: '3.0' sysadmin@test2:~/flask-quotes$ docker-compose up -d Starting flaskquotes_html_1 ... Starting flaskquotes_html_1 ... done sysadmin@test2:~/flask-quotes$ sysadmin@test2:~/flask-quotes$ curl localhost:20854 Hello World! Привет, мир! Сәлем Әлем! ¡Hola Mundo! नमस्ते दुनिया! 안녕하세요! Hallo Welt! 你好,世界! sysadmin@test2:~/flask-quotes$
2.2. Create the reverse proxy
Create sub-domain pandoc.example.com
Create your Reverse Proxy using these settings
server_name quotes.example.com;
proxy_pass http://localhost:20854;
Enable the Nginx Site
Restart Nginx
Verify using curl or using the web browser.