Welcome to the second article in our series of articles about container technologies in Fedora! This article will deal with Docker, a tool used to automate containerization of software using features of the Linux kernel.
What is Docker?
Docker is a high level set of tools that allows multiple isolated applications to run on a same host platform. Unlike other containerization software we talk about in this series, Docker is meant to run a system with a single process. In addition to providing these tools, Docker provides a “hub” for containers created by others.
Creating the container
Creating a container with Docker is extremely easy. We will be using the Docker command line tool to set up a Fedora 24 container named “fedora-container”. You’ll need to install Docker, if you don’t already have it, with the usual
Before it is possible to run a container, you will need to start the Docker daemon. To do this, run
. You can then run a container for Fedora using the command
, which will download an image for a basic Fedora container from Docker Hub.
Using the container
Docker is designed to run one process per container, but you can run more if you want to.
in your container alongside the process you had originally started. You can replace
with any command you’d like to run in the container.
The network will already be available, and you can use it to install packages using the standard DNF commands. You can stop the container either by stopping the Docker daemon, with
, or with
. You can then start the container again when you need it with
. It is also possible to temporarily pause execution of a container, using
Particularly useful is the
command, which you can use to copy files from and to the container. The command
will copy the file source from your home folder on the container to the name ‘target’ in the current folder, while
will copy in the reverse direction.
You can use images for other systems than Fedora by pulling images from the Docker Image Library. However, if you want to create and run applications or services using Docker, you will want to create your own images. Docker is able to create images automatically if you tell it how to in a Dockerfile. A Dockerfile contains the instructions and commands that will assemble the image you want to run in a container. The Dockerfile reference explains the format.
Fedora packages many example Dockerfiles that you can use to learn about Docker images and to create your own. You can install the Dockerfiles with
; they will be put in
. The Fedora Developer Portal has additional useful information about Docker in Fedora.