The Dockerfile contains a list of instructions that Docker will execute when you issue the docker build command. You’ll see in the tutorial that a Dockerfile is a step by step definition of building up a Docker image.
This will actually happen most of the time, which means that learning about the Dockerfile is a pretty essential part of working with Docker. You’ll want to create your own Dockerfile when existing images don’t satisfy your project needs. You’ll use a Dockerfile to create your own custom Docker image, in other words to define your custom environment to be used in a Docker container. So let’s go back to the definition: A Dockerfile is a text file that defines a Docker image. Why and when you’d want to use a Dockerfile? While your image layers are read-only, the additional layer added by the container is read-write. These layers contain the files and configuration needed by your environment.Īs you start up a container with docker run, Docker will add another layer on top of your image. An image, as you’ll see in the videos, is a layered representation of your environment. You just need to search for your preferred tech component, pull the image from the store with the docker pull command and you are ready to start up containers.Ĭontainers are started from images with the docker run command. The main source of Docker images online is the Docker store. A Docker image is not a runtime, it’s rather a collection of files, libraries and configuration files that build up an environment. A Docker image is a pre-built environment for a certain technology or service. You can start containers to run all the tech you can think of, you can run databases, web servers, web frameworks, test servers, execute big data scripts, work on shell scripts, etc.ĭocker containers are started by running a Docker image. You can think of this like one Docker container provides one service in your project.įor example you can start one container to be your MySQL database and start another container to be your Wordpress server and connect these containers together to get a Wordpress project setup. You usually run one main process in one Docker container. In order to follow this article you need to understand the following 2 basic concepts of Docker:ĭocker containers: containers are runtime environments. The main advantage is to avoid the situations when we say “it worked on my machine”, because Docker containers will give us the same environment on all machines. :)ĭocker’s main purpose is to give us run-time environments that we can re-create/reproduce on any machine (that runs Docker). It got 1,500 likes on Youtube from 120,000 views, so it’s not only me who says you’ll get this, so don’t worry. If you are absolutely new to docker, please start with the Getting started with Docker - step by step tutorial - article on the blog. Let me repeat a few basic concepts to better explain. Since this tutorial is for beginners let’s go slow and go deeper into the above definition.
What is a Dockerfile and why you’d want to use one?Ī Dockerfile is a text file that defines a Docker image. Please be patient, every part of it contains practical information, I hope you’ll find it useful. This is a pretty lengthy article (over 5500 words), you can think of it as a chapter of a Docker book. You’ll find the videos included in this article as you read and progress through the content. This article is the writeup of 2 Dockerfile video tutorials on my Youtube channel, meaning I created the videos first and I’m adding the details in written form now. We’ll go through a few examples of my workflow for creating my Dockerfiles and I’ll share my experience and best practices regarding working with Dockerfiles. Moreover I’ll explain why and in which situations you’ll want to use a Dockerfile in the first place. This article will help you understand the concept behind creating a Dockerfile. Dockerfile key instructions best practices.Start your Dockerfile with the steps that are least likely to change.Minimize the number of steps in the Dockerfile.