Creating a dockerfile

What is docker?

Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers.” -wikipedia

The key difference between a vm and a docker container is that docker virtualizes operating system and a virtual machine hardware

What is a dockerfile?

Dockerfile file is a list of instruction on how to build the container correctly, this can be handy for example web servers since with a dockerfile you can make instructions to copy the website html from the host (bare metal) system to the container running a webserver.

How to run docker containers?

To run a docker container first you need to install docker:

apt install

Docker hub is a place where you can find “images” for different applications and os’s. Here’s an example how to run python3 image:

  1. Go to docker hub and search “python”

2. Click on the “official” python one. now you should see a page like this:

3. For the third step copy the command from the docker hub site (“docker pull python”) and run it. This downloads the image to your system so that you can run it.

4. Now everything you have to do is run it, you can do that by running this commmand:docker run -it python

-i ==> interactive

-t ==> Allocate a pseudo-TTY

You should now have a python shell in front of you. Now that you know the basics of docker we can get into writing a dockerfile.

Writing a dockerfile

Create a new directory and create a file named “Dockerfile” in a text editor of your choice and write the commands below to the file.

FROM ubuntu

Loads ubuntu image as the virtual environment.

RUN mkdir /home/user1

Runs “mkdir /home/user1” inside the virtual ubuntu container

WORKDIR /home/user1

When you log into ubuntu you’ll start at /home/user1

COPY /tmp/work.txt /home/user1/work.txt

Copies tmp/work.txt from your host computer to /home/user1/work.txt

Save these lines to the “Dockerfile” file. make a directory called “tmp“ in the directory where you saved the Dockerfile file and put some text into a file called “work.txt” inside the tmp directory.

Now we need to build the dockerfile to actually run it. To do that run this command in the directory where the Dockerfile is located:

docker build ./

You should get an id that looks something like 2fe57279559a. To run the container you need to run the command:

docker run -it <the container id>

You should see something like this if you did everything correctly:

If you want to read more about dockerfile commands, here is a great cheatsheet:

Thank you for reading ❤



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


Im a penetration tester, software developer from Finland