Note that this repository is only used for running a sample flask app
Ensure that you have the following installed on your system:
- python 3.x
- pip
Create a virtual environment as this prevents package conflicts and keeps your setup clean:
cd flask_app
python3 -m venv venv
source venv/bin/activate
#Once the virtual environment is active, proceed with the following:
pip install --upgrade pip
pip install flaskYou can then run your app within your virtual environment:
python app.pyEnsure that you have the following 3 files in the directory where you are about to run the commands:
- app.py
- Dockerfile (https://docs.docker.com/engine/reference/builder/)
- requirements.txt (https://pip.pypa.io/en/stable/reference/requirements-file-format/)
You may have to run the commands below in sudo if your user is not in a docker user group. To run docker as a non root user: https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user
# Build a docker image locally
docker build -t flask-app .
# Listing your built images
docker images
# Starting your local container with port mapping from host port to container port(-p) and in detached mode(-d)
docker run -d -p 8080:8080 flask-app
# List your running containers
docker ps
# List all your containers(Running and stopped)
docker ps -a
# To stop and remove your container
docker stop <container ID>
docker rm <container ID>
# To remove your docker images
docker rmi <image ID>
# To check your container logs
docker logs <container ID>
# To exec into your container
docker exec -it <container ID> /bin/bash
For all docker commands: https://docs.docker.com/engine/reference/commandline/cli/