Docker Images

Steps to create your own image

  1. OS (ubuntu?)

  2. Update apt repo

  3. Install dependencies using apt

  4. Install python dependencies withpip

  5. Copy source code to /opt

  6. Run web server with Flask command

Example:

FROM Ubuntu

RUN apt-get update
RUN apt-get install python

RUN pip install flask

COPY . /opt/source-code

ENTRYPOINT FLASK_APP=/opt/source-code/app.py flask run

Creating the Docker image with Poetry

Note 1: Poetry creates a virtual environment automatically to isolate poetry installations from local, but Docker already does this, so we don't need a virtualenv to be created. So virtualenvs.create is set to false.

Note 2: test is an if statement in bash. So this means, "If $USE_PRODUCTION_ENV == True, then print --no-dev" in the shell command.

Explicitly:

Note 3: Must move back into root directory since we are presently in the api directory as we ran WORKDIR /api.

Installing dependencies with Poetry and Docker

  • You can't just docker exec -it api /bin/bash into the container when you are missing a dependency because the Docker container would complain there is no module found, thus kicking you out of the bash terminal. This command disregards this because the docker service does not need to be up when using this command (still needs to be built though of course).

Last updated

Was this helpful?