An Intro Guide to Unmistifying the Dockerfile

Where it all begins?

Supposing I have a simple goal of running a container with Ubuntu and Java inside.

  1. Using docker run so it runs the given container for us.

What is the Dockerfile?

The dockerfile is nothing more than a means to creating our own images.

The difference between an Image and a Container

An image is a representation of how a container will be built.

Creating a Container

So I picked a folder in my computer and created a file called Dockerfile. In it, I added the following line :

FROM ubuntu:18.04

Giving instructions to the Dockerfile

FROM

This is a mandatory command used in all Dockerfiles to specify the starting point for the image that will be built.

FROM openjdk
FROM scratch

RUN

RUN is a pretty interesting command. It can be executed one or more times and it allows me to define which commands will be run in the layer creation step of the image.

FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install openjdk-8-jdk -y

CMD

CMD and RUN are pretty similar.

FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install openjdk-8-jdk -y
CMD touch hello-world

ADD and COPY

Pretty intuitive names, right?

FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install openjdk-8-jdk -y
ADD host-file transferred-host-file

WORKDIR

This command has the purpose of defining our work environment.

Endnotes

The image creation proccess is of utmost importance for anyone that wishes to learn about Docker.

Engineering student and software enthusiast. Check out my github profile at @gabrielpulga.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store