Build, Run and Push Docker Images with Flask App.

Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications, whether on laptops, data center VMs, or the cloud.

I wanted to give a try to docker. I’m using Arch linux so I used pacman to install the docker. I’m sharing a few links here which might help someone.

1. Installation

Official Docker Documentation :
Download Docker for Windows/Linux/Mac :
Demo Flask Repo with Dockerfile :
SharktoothFlask Docker Image :

Docker installation for Arch Linux.

If people are coming from linux like Arch/Manjaro then this will help you. First I used SNAP store to install the docker then I found few commands were not working properly. Follow the below steps to install Docker on Arch.

$ sudo pacman -S docker

The above command will ask you to start the installation by pressing [Y/n] just press Y and it will take some time to install the dependency packages along with docker.
After the completion of installation, start and enable the docker service.

$ sudo systemctl start docker
$ sudo systemctl enable docker

2. Verify the Installation

$ sudo docker version
The above command will return the status. If it is not then debug. :P

Let’s test the docker image and run

$ docker run docker/whalesay cowsay Hello there!
Status: Downloaded newer image for docker/whalesay:latest
< Hello there! >
                    ##        .            
              ## ## ##       ==            
           ## ## ## ##      ===            
       /""""""""""""""""___/ ===        
  ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~   
       \______ o          __/            
        \    \        __/             

You can try Hello World Image as well.

$ sudo docker run hello-world

3. Writing Flask App.

1. Create new folder.

$ mkdir sharktooth-flask
$ cd sharktooth-flask

2. Create file and add the following code.

from flask import Flask, render_template
app = Flask(__name__)

def hello_from_shark():
    return render_template('sharktooth_hello.html')

if __name__ == '__main__':, host='')

3. Create templates folder and add sharktooth_hello.html file with following content


Shark and Whale discussing
<img src="">

4. Create requirements.txt file


5. Create Dockerfile file and make sure it doesn’t have any file extension like .txt

FROM ubuntu:latest
MAINTAINER Codetarsier ""
RUN apt-get update -y
RUN apt-get install -y python3-pip python3-dev build-essential
COPY . /app
RUN echo $(ls -1 /app)
RUN pip3 install -r requirements.txt
ENTRYPOINT ["python3"]
CMD [""]

Obviously you have to user your name and email.

Now it is time to build your first docker image.

4. Build your docker image

Make sure that you are in the project folder.

$ sudo docker build -t sharktooth-flask:latest .

List available docker images on your machine,

$ sudo docker images

Run your docker image

$ sudo docker run -d -p 5000:5000 sharktooth-flask

Check running process

$ sudo docker ps -a

Open browser and visit http://localhost:5000 and flask app will be runnning.

5. Push Docker Image to Your Account

1. Create your docker account first at

2. Login to your docker account

$ export DOCKER_ID_USER='codetarsier'
$ sudo docker login

3. Tag your image.

$ sudo docker tag sharktooth-flask codetarsier/sharktooth-flask

4. Push your image.

$ sudo docker push codetarsier/sharktooth-flask:latest

If all goes well, visit your docker hub profile and look for the newly pushed image.{your-account-name}

My docker hub profile :


Post a Comment