in order to build the application, we need to use a Dockerfile. A Dockerfile is simply a text-based script of instructions that is used to create a container image
- Get the app from git
https://github.com/UniCourt/Analytics-Workshop1 ==> clone this repo or download zip
Unzip the file and cd into the app folder.
- Create a file named Dockerfile in the above folder with the following contents.
FROM python:3.7-alpine
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
CMD ["flask", "run"]
Contents of Dockerfile:
a. Get the base image: FROM python:3.7-alpine
. This pulls the base python 3.7 image.
b. Declaring environment variables.
c. Copy the custom code into the image by COPY . /app
and change working directory.
c. Install required packages in the image. RUN pip install -r requirements.txt
.
- Create a new requirements.txt file with following contents
Flask
psycopg2-binary
This will install Flask and psycopg2-binary, which is required for postgres connection.
- open a terminal and go to the app directory with the Dockerfile. Now build the container image using the docker build command
docker build -t app-new .
Start your container using the docker run command and specify the name of the image we just created
docker run app-new
Note: Do not panic if you see errors mentioned below in your terminal, this is because we do not have necessary things to connect to db
KeyError: 'POSTGRES_USER'
docker ps
This will list all the running containers.
docker stop <container if that you see when you run>