Docker, how I did it.

This is less of a guide and more of a retelling of how I did it. While I was trying to build the docker container I ran into several issues. I don’t really know how to use Docker very well. I understand what it is, and the basics, it’s not a hard concept, but I didn’t understand how to use it.

For those who may not be privy to what Docker is, it is containerization and you can ship a fully ready app with just a docker image. This is, of course, meant for servers. At this point I had gone through several guides on how to build a Flask Docker container. Eventually I found one that almost got me there. There were still a few things I was missing. As such I had to do some work.

FROM python:3.7.3-slim

COPY requirements.txt /
RUN pip3 install -r /requirements.txt

COPY ./app /app
WORKDIR /app

ENTRYPOINT ["./run.sh"]

Is what I ultimately settled on as working. This is running off a few assumptions.

  1. your code is compatible with this version of Python (Mine is)
  2. You have a valid requirements.txt in the same directory as your docker file
  3. You have run.sh in the app directory of your project
  4. you have your app stored in ./app.

So the code in ./app is not important.

run.sh is important. It’s contents are below

#!/bin/sh

gunicorn --chdir /app app:app -w 2 --threads 2 -b 0.0.0.0:8003

As you can see it’s pretty simple but it does start gunicorn

As part of the process my requirements.txt is pretty simple right now as well but will grow as this project grows.

click==7.1.2
Flask==1.1.2
Flask-JWT-Extended==4.0.2
gunicorn==20.0.4
itsdangerous==1.1.0
Jinja2==2.11.3
MarkupSafe==1.1.1
PyJWT==2.0.1
Werkzeug==1.0.1

As you can see everything you’d need to just get Flask up and running is here. This got the basic app up and running. Now I want to finish the login and session validation.

Leave a Reply

Your email address will not be published. Required fields are marked *