Introduction

Docker is an application that simplifies the application management process inside containers. The containers allow you to run the applications in isolated processes of resources. They are similar to the virtual machines, but the containers are more portable, respectful to the resources and more dependable of the host system.

In this tutorial, you will learn how to install and use Docker Community Edition (CE) on Ubuntu 18.04. You will install Docker itself, work with the containers and images, after transmit an image in a Docker referential.

Prerequisites

To follow this tutorial you will need:

A Ubuntu 18.04 server configured with a sudo user with non root access and a firewall An account on Docker Hub, if you want to create your own images and transmit to Docker Hub, like in the steps 7 and 8.

Step 1 - Docker Installation

The Docker installation package available in the official Ubuntu repository may not be the most recent version. To ensure you have the latest version, we will install Docker from the official Docker repository.

To do this, we will add a new package source, add the GPG key from Docker to ensure the validity of the downloads, and then install the package.

Start by issuing the code:

$

sudo apt update

After, install some packages to allow the apt to use the packages via HTTPS:

$

sudo apt install apt-transport-https ca-certificates curl software-properties-common

Then add the GPG key from the official Docker repository to your system:

$

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Add the Docker referential to the APT sources:

$

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"

Then, update the package database with the newly added repository Docker packages:

$

sudo apt update

Make sure you are about to install from the Docker repository instead of the default Ubuntu repository:

$

apt-cache policy docker-ce

You will see a data output like this, although the version number of Docker may be different:

Output of apt-cache policy docker-ce

docker-ce: Installed: (none) Candidate:== 18.03.1~ce~3-0~ubuntu== Version table: 18.03.1~ce~3-0~ubuntu 500 500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages

Note that docker-it's not installed, but the install candidate comes from the Docker repository for Ubuntu 18.04 (bionic).

Finally, install Docker:

$

sudo apt install docker-ce

Docker should now be installed, the demo is started and the process enabled to start at boot time. Verify that it is running:

$

sudo systemctl status docker

The data output should be similar to this one, showing that the service is active and running:

         

docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2018-07-05 15:08:39 UTC; 2min 55s ago Docs: https://docs.docker.com Main PID: 10096 (dockerd) Tasks: 16 CGroup: /system.slice/docker.service ├─10096 /usr/bin/dockerd -H fd:// └─10113 docker-containerd --config /var/run/docker/containerd/containerd.toml

The Docker installation now gives you not only the Docker service, but also the docker command line utility or the Docker client. We will see how to use the docker command later in this tutorial.

Step 2- Docker command without sudo (optional)

By default, the docker command can only be run by the root user or by a user in the docker group, created automatically during the Docker installation process. If you try to run the docker command without prefixing it with sudo or without being part of the docker group, you will get a data output like this:

  

docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?. See 'docker run --help'.

If you want to avoid typing sudo every time you run the docker command, add your user name to the docker group:

$

sudo usermod -aG docker ${USER}

To apply the new group membership, log out of the server and log back in, or type the following:

$

su - ${USER}

You will be prompted to enter your user's password to continue.

Confirm that your user is now added to the docker group by typing:

$

id -nG

 

anna sudo docker

If you need to add a user to the docker group to which you are not logged in, explicitly declare this username using:

$

sudo usermod -aG docker username

The rest of this article assumes that you are running the docker command as a user of the docker group. If you choose not to, please add sudo in front of the orders.

We will explore the docker command.

Step 3 - Using the Docker Command

Using docker is to pass it a chain of options and commands followed by arguments. The syntax takes this form:

$

docker [option] [command] [arguments]

To display all available subcommands, type:

$

docker

From Docker 18, the complete list of available subcommands includes:

                                        

attach Attach local standard input, output, and error streams to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes to files or directories on a container's filesystem events Get real time events from the server exec Run a command in a running container export Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers version Show the Docker version information wait Block until one or more containers stop, then print their exit codes

To view the available options for a specific command, type:

$

docker docker-subcommand - - help

To view system-wide Docker information, use:

$

docker info

Conclusion

Now you have Docker installed on your cloud server. We’ll continue to post some tutorials about Docker, so keep up with our community. Feel free to ask me any questions and collaborate with more content.