How to create a Dockerfile

How to create a Dockerfile

— Dockerfile is a text file, Which is in a specific format


How to create a Dockerfile

FROM python:3.6 <- Start from a base OS or another Image, In this case it is Debian OS with python installed

RUN pip install flask <- Install dependencies

COPY . /opt <- Copy source code from host on to docker image

EXPOSE 8080 <- This is an docker instruction that image created will be listing to 8080 port

WORKDIR /opt <- Set the working directory to /opt

ENTRYPOINT [“python”, “”] <- We can specify a command in the entry point, So that it will run when it run as a container

Docker build the image in Layered architecture

FROM python:3.6 <- Layer 1

RUN pip install flask <- Layer 2

COPY . /opt <- Layer 3

EXPOSE 8080 <- Layer 4

WORKDIR /opt <- Layer 5

ENTRYPOINT [“python”, “”] <- Layer 6

Docker history command help to get the size on each layer

Docker history <Image name>


All the layers are cached in the docker, Let say if the build failed in layer 3, and we do some changes and rerun the build, it will started from where it left. In this case it is started from layer3.

Similar Posts