In this guide, we will see what is Docker, how to install Docker in Ubuntu Linux. In addition, we will also how to install Docker compose, a tool to define and run multi-container Docker applications.
What is Docker?
Docker is a fast, lightweight and OS level virtualization technology for developers and system administrators who wants to build an application with all of required dependencies, and ship it out as only one package.
Unlike other Virtualization methods, such as VMWare, Xen and VirtualBox, there is no need of separate guest operating system for each virtual machine.
All Docker containers efficiently share the host operating system's Kernel. Each container will run in an isolated userspace in the same operating system.
Docker containers will also run on any Linux variant. Let us say you're working in Fedora, and I am using Ubuntu. We can still develop, share and distribute the Docker images with each other.
You don't have to worry about the OS, software, customized settings, or anything. We can continue the development as long as we have Docker installed in our host system. Simply put, Docker will work everywhere!
You read two terms in the above paragraphs namely Docker images and Docker containers. You might wonder, what are they actually and what is the difference between them?
In layman's terms, a Docker image is a file which describes how a Container should behave, whereas Docker container is the running (or stopped) state of the Docker image.
Hope you got a basic idea about Docker. Refer official Docker user guide for more details. The link is attached at the end of this guide.
Docker Requirements
To install and configure Docker, your system must meet the following minimum requirements.
- 64 bit Linux or Windows operating systems ;
- If you're on Linux, the Kernel version should be 3.10 or above.
- Your system should be connected with Internet.
In Linux, to verify the Kernel and architecture details, run the following command from the Terminal:
$ uname -a
Sample output:
Linux ubuntuserver 4.15.0-91-generic #92-Ubuntu SMP Fri Feb 28 11:09:48 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
As you see in the above output, my Ubuntu system's kernel version is 4.15.0-91-generic and my Ubuntu system's architecture is 64 bit (x86_64 x86_64 x86_64 GNU/Linux). Check the bold letters in the above result.
Well, the Kernel version is higher than the minimum requirement, and the arch is 64 bit. So, we can install and use Docker without any problems.
Please note that it doesn't matter which Ubuntu OS you use. Also, It doesn't matter whether you use Ubuntu Desktop or Ubuntu Server edition or any other Ubuntu variants such as Lubuntu, Kubuntu, Xubuntu.
Docker will work just fine as long as you have the Kernel version 3.10+, and your system's arch is 64 bit.
Install Docker in Ubuntu 18.04 LTS
First of all, update your Ubuntu system.
To do so, open your Terminal, and run the following commands one by one:
$ sudo apt-get update
$ sudo apt-get upgrade
Docker is not available in the official Ubuntu repositories. So we will add the Docker repository to get the latest version of Docker.
First of all, install the necessary certificates and to allow apt package manager to use a repository over HTTPS using command:
$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Next, add Docker's official GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Verify whether the key has been added with the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint:
$ sudo apt-key fingerprint 0EBFCD88
You should see an output like below.
pub rsa4096 2017-02-22 [SCEA] 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 uid [ unknown] Docker Release (CE deb) <[email protected]> sub rsa4096 2017-02-22 [S]
Add the Docker official repository:
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Finally, run the following command to install latest Docker CE in Ubuntu 18.04 LTS server:
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
You can, of course, install a specific Docker version as well. To check the list of available Docker versions, run:
$ apt-cache madison docker-ce
Sample output:
docker-ce | 5:19.03.8~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:19.03.7~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:19.03.6~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:19.03.5~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:19.03.4~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:19.03.3~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:19.03.2~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:19.03.1~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:19.03.0~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:18.09.9~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:18.09.8~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:18.09.7~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:18.09.6~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:18.09.5~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:18.09.4~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:18.09.3~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:18.09.2~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:18.09.1~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:18.09.0~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 18.06.3~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 18.06.2~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 18.06.1~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 18.06.0~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 18.03.1~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
You can pick any available version from the above list and install it. For instance, to install version 5:18.09.2~3-0~ubuntu-bionic, run:
$ sudo apt install docker-ce=5:18.09.2~3-0~ubuntu-bionic docker-ce-cli=5:18.09.2~3-0~ubuntu-bionic containerd.io
Once it is installed, verify if the Docker service is running with command:
$ systemctl status docker
You'll see an output something like below.
● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2020-04-10 10:39:00 UTC; 3min 40s ago Docs: https://docs.docker.com Main PID: 14610 (dockerd) Tasks: 8 CGroup: /system.slice/docker.service └─14610 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock Apr 10 10:38:55 ubuntuserver dockerd[14610]: time="2020-04-10T10:38:55.800086650Z" level=warning msg="Your kernel does not support swap memory limit" Apr 10 10:38:55 ubuntuserver dockerd[14610]: time="2020-04-10T10:38:55.801329697Z" level=warning msg="Your kernel does not support cgroup rt period" Apr 10 10:38:55 ubuntuserver dockerd[14610]: time="2020-04-10T10:38:55.801659115Z" level=warning msg="Your kernel does not support cgroup rt runtime" Apr 10 10:38:55 ubuntuserver dockerd[14610]: time="2020-04-10T10:38:55.802348633Z" level=info msg="Loading containers: start." Apr 10 10:38:57 ubuntuserver dockerd[14610]: time="2020-04-10T10:38:57.965216155Z" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Apr 10 10:38:58 ubuntuserver dockerd[14610]: time="2020-04-10T10:38:58.779021136Z" level=info msg="Loading containers: done." Apr 10 10:38:59 ubuntuserver dockerd[14610]: time="2020-04-10T10:38:59.283684712Z" level=info msg="Docker daemon" commit=afacb8b7f0 graphdriver(s)=overlay2 version=19.03. Apr 10 10:38:59 ubuntuserver dockerd[14610]: time="2020-04-10T10:38:59.286277513Z" level=info msg="Daemon has completed initialization" Apr 10 10:39:00 ubuntuserver systemd[1]: Started Docker Application Container Engine. Apr 10 10:39:00 ubuntuserver dockerd[14610]: time="2020-04-10T10:39:00.306773751Z" level=info msg="API listen on /var/run/docker.sock"
Great! Docker service is up and running!
If it is not started already, run the following command to start it.
$ sudo systemctl start docker
Enable Docker service to start automatically on every reboot:
$ sudo systemctl enable docker
The installed Docker version can be found using command:
$ sudo docker version
Sample output:
Client: Docker Engine - Community Version: 19.03.8 API version: 1.40 Go version: go1.12.17 Git commit: afacb8b7f0 Built: Wed Mar 11 01:25:46 2020 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 19.03.8 API version: 1.40 (minimum version 1.12) Go version: go1.12.17 Git commit: afacb8b7f0 Built: Wed Mar 11 01:24:19 2020 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.2.13 GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429 runc: Version: 1.0.0-rc10 GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd docker-init: Version: 0.18.0 GitCommit: fec3683
Testing Docker
Let us go ahead, and test whether Docker is working or not.
To do so, run:
$ sudo docker run hello-world
The above command will download a test Docker image, and execute a sample hello_world program inside the container.
If you see an output something like below, congratulations! Docker is working fine in our Ubuntu system.
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:f9dfddf63636d84ef479d645ab5885156ae030f611a56f3a7ac7f2fdd86d7e4e Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
Great! Docker is ready to use.
Run Docker as non-root user in Linux
By default, the Docker daemon binds to a Unix socket instead of a TCP port. Since that Unix socket is owned by the root user, the Docker daemon will only run as the root user. Hence, the normal users can't perform most Docker commands.
If you want to run Docker as non-root user in Linux, refer the following guide:
Install Docker Compose in Ubuntu
Docker Compose is a tool that can be used to define and run multi-container Docker applications. With Compose, you use a Compose file to configure your application’s services. Then, using a single command, you can create and start all the services from your configuration.
We can install Docker Compose using any one of the following methods.
Method 1:
Download the latest Docker Compose from here.
As of writing this, the latest version was 1.25.5.
Run the following command to download latest stable Docker compose file:
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
If a new version is available, just replace the number 1.25.5 in the above command with new version number.
Finally, apply executable permissions to the binary using command:
$ sudo chmod +x /usr/local/bin/docker-compose
Method 2:
Alternatively, we can install Docker Compose using PIP. Pip is a python package manager used to install applications written in Python programming language.
Refer the following guide to install Pip on your system.
Once pip installed, run the following command to install docker compose. The following command is same for all Linux distributions!
$ pip install docker-compose
After installing Docker Compose, you can check the version with command:
$ docker-compose --version
You will see an output something like below.
docker-compose version 1.25.5, build 8a1c60f6
Congratulations! We have successfully installed Docker Community Edition and Docker Compose.
I installed Docker, now what? Check the next article in this series to learn the Docker basics.
To install Docker in RPM based systems such as RHEL, Fedora, CentOS, Scientific Linux and openSUSE, check the following link.
Also, download and use the following Docker Ebooks to get to know more about Docker.
And, that's all for now. I hope this helps.
Resource:
2 comments
What about Ubuntu 16.04?
This Guide is now updated to Ubuntu 16.04 LTS.