In this tutorial, we will cover the steps needed for installing Docker on Ubuntu 18.04.
Docker is mainly a software development platform and a kind of virtualization technology that makes it easy to develop and deploy apps inside of neatly packaged virtual containerized environments. Docker containers can be deployed to any machine without any compatibility issues, so the software stays system agnostic, simpler to use, less work to develop and easy to maintain and deploy.
Docker is a form of virtualization but, unlike a Virtual Machine, the resources are shared directly with the host. Let’s begin with the installation.
Requirements:
- For the purposes of this tutorial, we will use an Ubuntu 18.04 VPS.
- Full SSH root access or a user with sudo privileges is also required.
Step 1. Connect via SSH
Connect to your server via SSH as the root user using the following command:
ssh root@IP_ADDRESS -p PORT_NUMBER
and replace “IP_ADDRESS” and “PORT_NUMBER” with your actual server IP address and SSH port number.
Before starting with the installation you will need to update your system packages to their latest version.
You can do this by running the following command:
apt-get update apt-get upgrade
Once the upgrade is completed we can move on to the next step.
Step 2. Install Docker on Ubuntu 18.04
To get the latest version of Docker, we will install it from the official Docker repository. We will add a new package source, and add the GPG key from Docker to be able to verify that the downloads are valid.
We need to install a few prerequisite packages with the following command:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Now, we will add the GPG key for the official Docker repository and add the Docker repository to APT sources with the following commands:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
Next, we will update the package database with the Docker packages:
sudo apt update
and make sure that we will install Docker from the Docker repo instead of the Ubuntu repo:
apt-cache policy docker-ce
The output should be similar to this:
docker-ce: Installed: (none) Candidate: 5:18.09.5~3-0~ubuntu-bionic Version table: 5:18.09.5~3-0~ubuntu-bionic 500 500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages 5:18.09.4~3-0~ubuntu-bionic 500 500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages 5:18.09.3~3-0~ubuntu-bionic 500 500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages 5:18.09.2~3-0~ubuntu-bionic 500 500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages 5:18.09.1~3-0~ubuntu-bionic 500 500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages 5:18.09.0~3-0~ubuntu-bionic 500 500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages 18.06.3~ce~3-0~ubuntu 500 500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages 18.06.2~ce~3-0~ubuntu 500 500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages 18.06.1~ce~3-0~ubuntu 500 500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages 18.06.0~ce~3-0~ubuntu 500 500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages 18.03.1~ce~3-0~ubuntu 500 500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
Finally, we will install Docker with the following command:
sudo apt install docker-ce
To check that Docker is installed, daemon started and the process enabled execute the following command:
sudo systemctl status docker
The output should be similar to the following:
docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2019-05-01 11:06:05 UTC; 10s ago Docs: https://docs.docker.com Main PID: 4234 (dockerd) Tasks: 8 CGroup: /system.slice/docker.service └─4234 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
We successfully installed Docker. Now in the next steps, we will show you how to use the docker command.
Step 3. Using the Docker Command
The syntax of the Docker CLI command takes this form:
docker [option] [command] [arguments]
To list all available commands we need to run the docker command with no parameters:.
docker
The output should be similar to the following:
A self-sufficient runtime for containers Options: --config string Location of client config files (default "/root/.docker") -D, --debug Enable debug mode -H, --host list Daemon socket(s) to connect to -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem") --tlskey string Path to TLS key file (default "/root/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit Management Commands: builder Manage builds config Manage Docker configs container Manage containers engine Manage the docker engine image Manage images network Manage networks node Manage Swarm nodes plugin Manage plugins secret Manage Docker secrets service Manage services stack Manage Docker stacks swarm Manage Swarm system Manage Docker trust Manage trust on Docker images volume Manage volumes Commands: 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
If you want to see the options available to a specific command, execute the following command:
docker docker-subcommand --help
To view information about Docker:
docker info
Step 4. The Docker Command Line Interface
To search for an image from Docker Hub registry, we can use the following command:
docker search ubuntu
To download the official Ubuntu 18.04, we can do this by using the image pull subcommand:
docker image pull ubuntu
If there is no tag specified, Docker will pull the latest image.
We can list the images by using the following command:
docker image ls
If you want to remove the image for some reason, you can use the following command:
docker image rm ubuntu
If you need to start, stop, remove and manage a container you can do this with the docker container subcommand.
With the following command, we can start a Docker container:
docker container run ubuntu
If you need to interact the container via the command line, you can do this executing the following command:
docker container run -it ubuntu /bin/bash
To list all active containers, type:
docker container ls
but if you want to view both active and inactive containers, type:
docker container ls -a
To remove docker containers execute the following command:
docker container rm [container_id]
Those are just some of the things you can do with Docker – it’s a very versatile program.
In this tutorial, we learned how to install Docker on Ubuntu 18.04 and how to use the docker commands and command line interface.
Of course, you don’t have to install Docker on Ubuntu 18.04 if you use one of our Fully-Managed Server Support services, in which case you can simply ask our expert system administrators to install Docker on Ubuntu 18.04 for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this tutorial on installing Docker on Ubuntu 18.04, or if you found it helpful, please share it with your friends on the social networks by using the share shortcuts below, or simply leave a comment in the comments section. Thank you.