Problem solve Get help with specific problems with your technologies, process and projects.

Steps to install Docker on Ubuntu 16.04 servers

If IT wants to maximize Docker's potential on Ubuntu 16.04 servers, know these steps and commands to ensure a smooth installation.

Containers enable organizations to expand beyond the standard server in ways that traditional technologies cannot....

With containers, you can bundle a piece of software within a complete file system that contains everything it needs to run: code, runtime, system tools, system libraries and so on. When you deploy an application or service this way, it will always run the same, regardless of its environment.

If you want to containerize a service or an app, you'll need to get up to speed with Docker, one of the most popular container tools. Here are some guidelines to install Docker on Ubuntu 16.04 servers and fulfill Docker's potential.

What to know before you install Docker on Ubuntu 16.04

Before you install Docker on Ubuntu 16.04, update the apt utility -- a package manager that includes the apt command -- and upgrade the server. If apt upgrades the kernel, you may need to reboot. If you need to reboot, do it when the server can be down for a brief period. It's important to note that you can only install Docker on 64-bit architecture, with a minimum kernel of 3.10.

To update and upgrade, enter the following commands:

sudo apt-get update

sudo apt-get upgrade

Once the update/upgrade is complete, you can install Docker with a single command:

sudo apt-get install -y docker.io

When the install completes, start the Docker engine with the command:

sudo systemctl start docker

Finally, enable Docker to run at boot with the command:

sudo systemctl enable docker

Running Docker as a standard user

Out of the box, you can only use Docker if you're the root user, or by way of sudo. Since either running Docker as the root user or with sudo can be considered a security risk, it's crucial to enable a standard user. To do that, you must add the user to the Docker group. Let's say we're going to add the user "Olivia" to the Docker group so that she can work with the tool. To do this, issue the following command:

sudo gpasswd -a olivia docker

Restart the Docker service with the command:

sudo systemctl restart docker

Once Olivia logs out and logs back in again, she can use Docker.

Docker terminology

Before we get into the commands to work with Docker, you'll need to understand some of its terminology.

  • Image: a frozen snapshot of live containers. Images are generally pulled from the Docker Hub, but you can create your own images. Images are read-only.
  • Container: an active, stateful instance of an image that is read-write.
  • Registry: a repository for Docker Images.

 In a nutshell, you pull images from a registry and run containers from those images.

Let's say you want to run a Debian Linux container so you can test or develop a piece of software. To pull down the Debian image, you should search the registry first. Issue the command docker search debian. The results of that search (Figure A) are important.

The results of a Docker search command.
Figure A. Docker search command results.

The first two listings are marked as "official." To be safe, always pull official images. Pull down that debian image with the command:

compliance_article_010.jpg

When the image pull is complete, Docker will report the image debian:latest has been downloaded. To make sure it's there, use the command:

docker images

The Debian command is ready to run.
Figure B. Debian is ready to run.

You are now ready to create the debian container with the command:

compliance_article_010.jpg

The above command will return a hash to indicate that you've created a container.

The Debian container has now been created.
Figure C. How to create a Debian container.

To run the container, issue the command:

docker run -i -t debian /bin/bash

The above command will run the debian container. It keeps STDIN (standard input) open with the -i option, allocates a pseudo-tty with the -t option, and places you in a Bash prompt so you can work. When you see the Bash prompt change, you'll know that the command succeeded.

The Debian container has been installed and works in the system.
Figure D. The Debian container is now working.

You can work within your container and then exit the container with the command exit.

Commit changes

After you install Docker on Ubuntu 16.04, let's say you want to develop an image to be used later. When you exit a running container, you will lose all of your changes. If that happens, you cannot commit your changes to a new image. To commit those changes, you first need to run your container in the background (detached), by adding the -d option:

docker run -dit debian

When you run the container like this, you can't make any changes because you won't be within the container. To gain access to the container's shell, issue the command:

docker exec -i -t HASH /bin/bash

HASH is created after running the image in the background -- it will be a long string of characters.

Now, you should be inside the running container. Make your changes and then exit the running container with the command exit. If you re-enter the container, your changes should still be present.

To commit your changes to a new image, issue the command:

docker commit HASH NAME

HASH is the hash for our running container and NAME is the name you'll give the new image.

If you now issue the command docker images, your newly created image will be listed alongside the image you pulled from the Docker Hub registry.

The test images has been created.
Figure E. The newly created test image.

Next Steps

Compare different Linux distros for servers

Learn how to perform a Docker backup

Other deployment container options outside of Docker

This was last published in April 2017

Dig Deeper on Linux servers

PRO+

Content

Find more PRO+ content and other member only offers, here.

Join the conversation

1 comment

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

What issues have arisen during your Docker installation?
Cancel

-ADS BY GOOGLE

SearchWindowsServer

SearchServerVirtualization

SearchCloudComputing

Close