Docker Images
Steps to create your own image
OS (ubuntu?)
Update
apt
repoInstall dependencies using
apt
Install python dependencies with
pip
Copy source code to
/opt
Run web server with Flask command
Example:
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