Skip to main content

Docker - Image Creation

Building a Docker File

A docker file is essentially a list of instructions that are issued to Docker to build an image. You will more than likely want to build your Docker File somewhere that you can access all the files required for the application you're dockerising.

To create a docker image, you first need to a list of every step required for installing/configuring the application on bare metal. As a basic example, I have an application which requires the following;

Ubuntu 22.04
apt update
apt install -y python python-pip
application code in /opt/app.py
command to run app

Docker File for this app;

FROM ubuntu #Define base image to use for the container

RUN apt-get update
RUN apt-get install -y python python-pip #Install required packages, use -y flag to accept install without manual intervention
RUN pip install flask #Install Flask module for web app

COPY app.py /opt/app.py #Copy the app source code from current directory file 'app.py' to /opt/app.py on the container

ENTRYPOINT FLASK_APP=/opt/app.py flask run --host=0.0.0.0 #Command to run the application

 Once we've created our Docker File, we then use the Docker Build command