Docker is an amazing tool that solves the age-old problem between developers and system administrators – developers say an app works on their machine, while system admins worry about changing libraries and requirements. With Docker, this problem goes away. In this tutorial, we’ll show you how to install Docker on Ubuntu 18.04.
Docker is essentially a virtual machine, that lets you run images. With Docker, you don’t need to worry about the requirements! That’s a perfect fit for many VPS projects.
Docker is an open source technology that is used to deploy applications through containers. It is relatively new but receives constant improvements! Docker is highly popular among developers and can be installed without any problems in our favorite Linux distribution. In this case, we’ll be covering how to install Docker on Ubuntu!
The main novelty of Docker is that it allows to “package” an application or a set of services in containers. A Docker container is an instance of an application that contains all the libraries and components necessary for an application to work. From a practical point of view, a container is a kind of reduced virtual machine that functions independently from the operating system where a specific application or service is executed.
A Docker container is generated from an image which is the result of the packaged app or service. It can contain a complete operating system or pre-installed applications. That is to say, from an image is that the container will start to work.
There are many Docker images that we can use in our daily work cycle. We can also create our own images and further expand the possibilities of this great application.
So with this in mind, let’s learn how to install Docker on Ubuntu 18.04.
How to Install Docker on Ubuntu 18.04
Docker is not in the official Ubuntu 18.04 repositories. However, the installation process will not be complicated for because of it. Let’s start:
1. Access Your VPS
First, we have to connect to the server using SSH. If you’re having trouble, check out our PuTTY tutorial.
2. Update Your System
Then, the system needs to be updated to make it safer and reliable for the Docker installation. Run the following two commands:
sudo apt update
sudo apt upgrade
3. Install Prerequisite Packages
Once we have updated the system, we need to install some necessary packages before installing Docker. You can do this with the help of a single command:
sudo apt-get install curl apt-transport-https ca-certificates software-properties-common
4. Add the Docker Repositories
Now we have to add the Docker repositories. This will make the installation process much easier. This enables us to use the officially supported method of the installation.
First, we add the GPG key, by entering the following command in the command line:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Next, we add the repository:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
After that, just update the repository information:
sudo apt update
5. Install Docker on Ubuntu 18.04
We’re almost done! Use the apt command to install Docker:
sudo apt install docker-ce
6. Check Docker Status
Once the installation is complete, it is a good idea to check the status of the service.
sudo systemctl status docker
That’s it, you now know how to install Docker on Ubuntu 18.04. Easy, right? Let’s learn some Docker basics!
How to Start Using Docker on Ubuntu 18.04
Once Docker is installed, all we need to do is use the test image to check that everything is working as it should. Do this with the following command:
sudo docker run hello-world
Now, if we want to search for available images we just have to use the following command:
sudo docker search [search_query]
Just replace your query with the bracketed text.
For example, if we want to search for an image related to Debian, the command and output will look like this:
sudo docker search debian
Then, to download the image to our computer, we will use the name of the image along with the following command:
sudo docker pull [image_name]
In the real world, the command will look like so:
sudo docker pull debian
Normally, users will have several images in their system. We can list them with the command:
sudo docker images
The list will look much like the one you receive when you enter a search query.
After that, we can execute our image using the pull command and the Image ID.
sudo docker run -i -t [image]
There are options that extend the functionality of the command itself. For example, the –i option makes the image execution interactive. Or the -d option that executes it in the background.
Once we are running an image, we can end its execution by using the key combination CTRL+D.
Finally, if we want to use Docker without root privileges, we need to run the following command:
sudo usermod -aG docker $(whoami)
After that, restart the system, and the changes will be applied.
Docker’s advantages make software deployment much more efficient than before. Thanks to this, developers will have no problems in knowing how your application will run outside the test environment. On the other hand, the sysadmin will not have to struggle with system changes or looking for necessary libraries.
In this tutorial, we showed you the first steps to take with Docker. To unlock the true power of this amazing utility, we recommend to check out the official documentation. Happy developing!