One of the main advantages of using Linux as a platform for your server is containers. Containers are a technology that allows a user to contain a micro-operating system, and a specialized piece of software and run it isolated on the system. Doing this allows for incredible performance, and flexibility. When talking about containers on Linux, the most popular solution out there is Docker. This software, once installed, makes it very easy for just about anyone to easily install and run containers on the fly. Here’s how to get Docker on Linux..
Before getting Docker CE running on your Ubuntu server or desktop, you should update the Ubuntu apt package cache, and install any software updates that may need installing.
sudo apt update sudo apt upgrade
Once your system is up to date, you’ll need to install a few packages. These packages are important, and will allow Ubuntu’s package manager to better interact with downloads over HTTPS.
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
The next step in the installation process is to add the GPG key for the official Docker software repository. This is important, as Ubuntu will not install the software without it.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
With the key downloaded, add the official Docker CE software repository to your Ubuntu system.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Lastly, update Ubuntu’s software sources again and install the Docker software to finish the installation process.
RECOMMENDED FOR YOU
sudo apt updatesudo apt install docker-ce
Before installing Docker CE for Debian, update the system. This will ensure Docker runs well on your machine.
sudo apt-get update sudo apt-get upgrade
With everything up to date, you’ll need to install a few tools to ensure the Docker CE packages download correctly. Keep in mind that the instructions will be different depending on your release of Debian.
Debian Stretch/Jesse Instructions
sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common
sudo apt-get install apt-transport-https ca-certificates curl python-software-properties
With the tools added, it’s time to install the Docker repo’s GPG key to Debian. This is a critical step, so do not ignore it. Debian will not install Docker without it.
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | sudo apt-key add -
Then, add the Docker CE software repository to your Debian sources list.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") $(lsb_release -cs) stable"
All that’s left to do now is to update Debian’s software sources a second time, and install Docker CE. Do this with the following commands:
sudo apt-get updatesudo apt-get install docker-ce
Before installing Docker on Fedora, you’ll need to install some Dnf plugins. These are important, and will allow the installation of the Docker software to be much easier. Install the Dnf plugins with:
sudo dnf -y install dnf-plugins-core
With the plugins installed, it’s time to add the actual software repository to the machine.
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
Adding the official Docker CE software repository to Dnf and Fedora means that as the user updates their system they’ll get regular Docker updates. If you’re installing Docker on a PC that doesn’t have regular access to the internet, consider going to the Docker CE download page and instead grabbing an RPM.
Install Docker CE directly from the Fedora package manager to complete the process.
sudo dnf install docker-ce
Docker is well supported on Linux. The Linux distributions above are some of the ones that Docker prefer you use. If you’re looking to get the software on a different version of Linux, it’s a good idea to check out the documentation. Docker installation information is a wonderful tool, and they have a lot of write-ups for many different Linux distributions. Also check the documentation for the Linux distribution you use, as it may also help you get the docker software installed.
Enabling Docker CE
Docker CE is installed, but before you can use it, you’ll need to use the init system to enable its services. Depending on the operating system you use, instructions may be different. For example, if you’ve followed the Ubuntu or Debian instructions, there’s a good chance systemd items have automatically been turned on during the installation process. Fedora, or other Linux distributions that make use of systemd will need to enable these items separately.
First, enable the service at startup using the systemctl enable command.
sudo systemctl enable docker
Then, immediately start docker on the system with the systemctl start command.
sudo systemctl start docker
Want to disable the Docker CE service? Use systemctl disable.
sudo systemctl disable docker
In addition, stop Docker at any time by using systemctl stop, and restart it with systemctl restart.
sudo systemctl stop sudo systemctl restart
Using Docker CE
With Docker CE installed on Linux, you can install and use as many containers as you like. To test and make sure that the Docker CE software is working correctly, you should first run the test container:
sudo docker run hello-world
If the hello-world container launches and works correctly, everything is good to go. If not, re-install Docker and try again.
Install And Run Containers
Installing containers to your Docker setup is pretty straight-forward. To start, search Docker Hub for a container you’d like to install.
docker search searchterm
Then, install it with docker pull.
docker pull containername
Run the container with:
sudo docker run containername