The Flask Application uploaded to my GitHub Here
I will dockerize the above application and show you the steps to do that
Let’s Start ๐ค
- First will add some files i don’t want to Dockerignore file
vim .dockerignore
.dockerignore
Dockerfile
.gitignore
Pipfile.lock
migrations/
- Write the dockerfile, which is already included to the above Repo vim Dockerfile
FROM python:3
ENV PYBASE /pybase
ENV PYTHONUSERBASE $PYBASE
ENV PATH $PYBASE/bin:$PATH
RUN pip install pipenv
WORKDIR /tmp
COPY Pipfile .
RUN pipenv lock
RUN PIP_USER=1 PIP_IGNORE_INSTALLED=1 pipenv install -d --system --ignore-pipfile
COPY . /app/notes
WORKDIR /app/notes
EXPOSE 80
CMD ["flask", "run", "--port=80", "--host=0.0.0.0"]
- Build and Test
docker build -t notesapp:0.1 .
docker run --rm -it --network notes -v /home/Osama/notes/migrations:/app/notes/migrations notesapp:0.1 bash
The above commands build and run the container, once you are inside the container configure the database
- Configure Database
flask db init
flask db migrate
flask db upgrade
- Run and Upgrade
docker run --rm -it --network notes -p 80:80 notesapp:0.1
- In a web browser, navigate to the public IP address for the server, and log in to your account.
- Verify that you can create a new note.
Perfect , we are done now
Enjoy the learning ๐
Osama