How to install Docker in Ubuntu 18.04? - Step by Step guide to install and use Docker in Ubuntu 18.04
In this tutorial we are going to use fresh installation of Ubuntu 18.04 and then installer Docker on the operating system. We will show you how to start, stop and use the Docker on Ubuntu 18.04. After following this tutorial you will be able to install Ubuntu 18.04 on your system. For this tutorial we are running the Ubuntu 18.04 in Oracle Virtualbox, but this tutorial applies for all other installation of Ubuntu 18.04 including server installation.
The tutorial below will give you an overview of Docker and then guide you step by step to help you in installing Docker successfully on Ubuntu 18.04. After the installation of Docker you will learn to use the Docker command-line interface (CLI) in Ubuntu 18.04, which helps in running the Docker images on your system. The tutorial assumes you already know the basic Linux command and you have a Ubuntu 18.04 desktop or VM installed to proceed with.
Docker prerequisites
You should have sudo access to your Ubuntu 18.04 desktop and have sufficient privileges to install software on your system. You should know how to use the apt-get package manager to install software on Ubuntu box. We are giving you all the steps of downloading, installing, configuring and using the Docker image on Ubuntu based operating system.
What is Docker?
Docker is a lightweight container-hosting service that lets developers push application code into a container and run on remote server. This is used by millions of developers around the world to package their application and run on the remote servers very efficiently. The application along with required dependency is packaged into a container called Docker container and can be run on any machine having Docker service. As with any other build tool, you can build applications as-is or create custom script to build your Docker image.
Installing Docker on Ubuntu 18.04
Now let's get started and install Docker on Ubuntu 18.04.
Step 1: Login to your Ubuntu 18.04 box and update
Enter username and password for your system and login to the box.
Step 2: Update the system
First of all you should update your system to include latest updates in the packages by running the following command:
sudo apt update
Here is the screen shot of updating the system:
Step 3: Installing the pre-requisite packages
Now we have to install the pre-requisit package necessary for Docker. Here is the command to install the pre-requisites packages:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
The next step is to add the the GPG key of the official Docker repository in the system so that it will be able to download the files for installation of Docker. Run the following command on your system in terminal:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Step 4: The next step is to update the system to discover Docker packages from the repo, run following command:
sudo apt update
Step 5: Now we have to add the Docker repository to APT sources using following command:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
Run the updates with following command:
sudo apt update
Step 5: Set docker-ce repository ad default
Run the following command to use docker-ce repository as default instead to Ubuntu repository:
apt-cache policy docker-ce
Step 6: Install Docker on your system
Now are ready to install Docerk from the Docker repo. Run the following command to install Docker on your system:
sudo apt install docker-ce
Step
7: Checking Status of Docker
After completion of installation of Docker you can check its running status with following command:
sudo systemctl status docker
If Docker is running on your system then it will show following output which shows its running status:
Step 8: Getting Docker information
Now you can run the following command to see the docker information: 0
docker info
Above command will display the Docker information along with your system information.
Step 9: Running your First container
Now we will run our first container which is actually distributed at Docker Hub and the image is pulled automatically from the Docker Hub. Here is command to run the "Hello World" Docker container: 1
docker run hello-world
Output of the command:
docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 0e03bdcc26d7: Pull complete Digest: sha256:49a1c8800c94df04e9658809b006fd8a686cab8028d33cfba2cc049724254202 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/
Above command runs the 'hello-world:latest' and displays "Hello from Docker!" on the console along with other information.
Step 10: How to restart Docker?
The systemctl command is used to stop, start and restart the docker service. Here is the command that you can run to restart Docker service on your Ubuntu 18.04: 2
sudo systemctl restart docker
In this tutorial you learned to install Docker on Ubuntu 18.04 operating system then run first "Hello World" Docker container on newly installed Docker.
Here are more tutorials of Docker: