Edited 3 weeks ago by ExtremeHow Editorial Team
DockerUbuntuContainerizationInstallationLinuxOperating SystemsSoftwareConfigurationSystemDevelopment
This content is available in 7 different language
Docker is a popular tool that allows developers to automate the deployment, scaling, and management of applications inside lightweight containers. These containers help replicate production environments for testing and development purposes without the overhead of a full virtual machine. In this comprehensive guide, we will walk you through the process of installing and configuring Docker on a system running the Ubuntu operating system. This guide will cover everything from basic setup to fine-tuning the configuration to your needs.
Before we start the installation of Docker on Ubuntu system, you need to fulfill some pre-requisites.
The first and foremost thing is to make sure that your system packages are up-to-date. This is important to avoid any compatibility issues during Docker installation.
sudo apt update sudo apt upgrade
The above commands will update the package list and upgrade the installed packages on your Ubuntu system.
Before we can install Docker, we need to install several prerequisite packages that will facilitate a smooth installation process.
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Here's what each of these packages does:
For security purposes, we need to add the official GPG key of Docker to our system. This ensures that the packages downloaded from Docker are authentic and secure against any tampering.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
After executing the above command, the official key of Docker will be added. This is required for the installation package verification process.
To install the latest version of Docker, you need to configure the Docker repository. We will add the Docker repository to APT's sources so that Ubuntu can download Docker packages directly from it.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
This command adds Docker's repository using APT's add-apt-repository tool. $(lsb_release -cs) captures the name of your Ubuntu version, automating the process for different Ubuntu releases.
Now that the Docker repository has been added to your APT configuration, you can go ahead and install Docker itself.
sudo apt update sudo apt install docker-ce
This step installs a Docker package called docker-ce, where "ce" means Community Edition, which is the open-source version of Docker.
Once the installation is complete, you can verify if Docker is installed and running correctly on your system. Here’s how you can do it:
sudo systemctl status docker
This command will show you the status of the Docker service. A well-running Docker service will be represented by the active (running) status.
To confirm that everything is working as expected, try running Docker's Hello World container. This is a small container image that simply outputs the message "Hello from Docker!".
sudo docker run hello-world
If everything is okay, upon running this command you will get a message indicating that Docker is up and running.
By default, Docker runs with root privileges. If you want to avoid using sudo every time, or you're managing a shared development environment, adding your user to the Docker group can make it simpler.
If it doesn't already exist, create a Docker group with the following command:
sudo groupadd docker
Add your current user to the Docker group:
sudo usermod -aG docker $USER
After executing this command, you must log out and log in again for the changes to take effect.
To increase usability, especially on servers, configure Docker to start automatically when the system boots.
sudo systemctl enable docker
This ensures that Docker and its services start automatically whenever your machine reboots.
By default, the Docker configuration file is located at /etc/docker/daemon.json
. Making changes to this file allows you to define many parameters such as logging level, registry mirror, and more.
Here's a simple example of a daemon.json
file:
{ "log-level": "warn", "storage-driver": "overlay2", "tlscacert": "/path/to/ca.pem", "tlscert": "/path/to/server-cert.pem", "tlskey": "/path/to/server-key.pem", "hosts": ["tcp://0.0.0.0:2376", "unix:///var/run/docker.sock"] }
Change the paths and settings above to suit your needs. Always make sure to restart the Docker service after editing this file.
sudo systemctl restart docker
If you use a firewall, you must configure it so that Docker can communicate effectively on the required ports. Docker typically uses ports such as 2376 for communication.
For example, using UFW (Uncomplicated Firewalling), you can allow traffic as follows:
sudo ufw allow 2376/tcp
If you use a different port number than the default, be sure to replace it with the correct port number.
If for some reason you want to uninstall Docker, you can do so as follows:
sudo apt remove docker docker-engine docker.io containerd runc
This will remove Docker from your system, however for a complete clean you may need to remove additional dependencies using the autoremove command:
sudo apt autoremove
Docker is a powerful tool that provides developers and IT professionals with a standardized platform to build, share, and run applications. With this detailed guideline, you should install and configure Docker on your Ubuntu machine. Remember that the power of Docker lies in its ability to streamline the deployment of applications by creating containers that run reliably in different environments.
The guide above not only helps you start the Docker installation but also ensures that your system is well configured for optimal performance. Always make sure to keep Docker and its components up-to-date to enjoy the latest features and security patches.
If you find anything wrong with the article content, you can