Getting Started

We’ll get started with the Docker Quick Installation Guide, the minimal prerequisite to generate something to show for.

Next, create a place to work. This is usually a directory hierarchy in your home directory, that you can put under revision control.

The next few walk-through examples illustrate the usefulness of Docker in annotated fashion.

Example #1: Explore a Docker Container

For this first exercise, we’re going to run a few Fedora 20 Docker containers and poke at them.

First, let’s pull the relevant Docker container:

$ docker pull docker.io/library/fedora:20

Note that this can be shortened since docker.io is the default registry. The following command should not result in you downloading the image all over again:

$ docker pull library/fedora:20

And in fact, library is the repository name for official images, so the command can yet again be shortened.

$ docker pull fedora:20

Let’s verify the version of the fedora-release package in the image:

$ docker run fedora:20 rpm -qv fedora-release
fedora-release-20-4.noarch

Success!

Example #2: Fedora 20 Welcome Page

Create a directory example-2/, with a file named Dockerfile containing the following:

1
2
3
4
5
6
7
FROM docker.io/library/fedora:20

RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-20-x86_64

RUN yum -y install httpd && yum clean all

CMD [ "/usr/sbin/httpd", "-DFOREGROUND" ]

A line-by-line explanation of the instructions for the image:

#1

Create the new image from the docker.io/library/fedora:20 base image.

#3

Runs the command specified inside the image.

A container is spawned based on the previous version of the image, which in this case specifically is the base image downloaded from the public Docker Hub.

The command that runs imports the GPG key used to sign the packages for Fedora 20 in to the RPM database of trusted keys, to prevent warnings [1].

Note

Arguably, this command should be a part of the docker.io/library/fedora:20 base image.

#5

Install the httpd software package using YUM.

Note

For Docker images to remain slim, clean out /var/cache/yum/ which will contain repository metadata even after the installation of the package has been successfully completed.

#7

Using the CMD directive, specify that the command specified in the JSON-formatted array (i.e. “list”) should be run.

Todo

why not systemd?

Todo

also, ENTRYPOINT

Build the Docker image:

$ docker build -t nulecule-docs/example-2 example-2/.

Run the Docker image:

$ docker run -it -p 172.17.42.1:80:80 nulecule-docs/example-2

Now, visit http://172.17.42.1/

Todo

Explain the build command

Todo

Explain the run command

Todo

Stop the container (Ctrl-C)

Example #3: CentOS 7 Welcome Page

Create a directory example-3/ and put a file named Dockerfile in it, containing the following:

1
2
3
4
5
6
7
FROM centos:centos7

RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

RUN yum -y install httpd && yum clean all

CMD [ "/usr/sbin/httpd", "-DFOREGROUND" ]
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
--- docker/examples/fedora-20-welcome-page/Dockerfile
+++ docker/examples/centos-7-welcome-page/Dockerfile
@@ -1,6 +1,6 @@
-FROM docker.io/library/fedora:20
+FROM centos:centos7
 
-RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-20-x86_64
+RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
 RUN yum -y install httpd && yum clean all
 

Build the Docker image:

$ docker build -t nulecule-docs/example-3 example-3/.

Run the Docker image:

$ docker run -it -p 172.17.42.1:80:80 nulecule-docs/example-3

Now, visit http://172.17.42.1/

TODO: “Notice the difference?”

Footnotes

[1]Example Output without Importing GPG Key