Installing and running Docker on a Linux server
Learn how to install and setup Docker as a service.
There are two options for installing Docker:
- On a new server: Docker is available as a ready-to-use application which can be automatically installed on the server when it is built.
- On an existing server: Docker can be manually installed and configured on an existing server.
Requirements
To install on an existing server:
- A 64-bit Linux Cloud Server configured with a static IP address, running CentOS 7, Ubuntu 14.04, or Ubuntu 16.04.
- Kernel version 3.10 or higher.
vServer (VPS) from IONOS
Low-cost, powerful VPS hosting for running your custom applications, with a personal assistant and 24/7 support.
Install Docker on a new server
Log in to the Cloud Panel then go to Infrastructure > Servers.
Install Docker on Ubuntu 16.04
Update the package index:
sudo apt update
Install the required packages which will allow apt to use HTTPS to access the Docker repository:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Add the official Docker GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Verify that you have added the GPG key:
sudo apt-key fingerprint 0EBFCD88
The server should respond with the key fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88:
user@localhost:~# sudo apt-key fingerprint 0EBFCD88
pub 4096R/0EBFCD88 2017-02-22
Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid Docker Release (CE deb) <docker@docker.com>
sub 4096R/F273FCD8 2017-02-22
Add the stable repository:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Update the package index again:
sudo apt update
Install Docker:
sudo apt install docker-ce
After the installation is complete, the Docker daemon will start automatically.
Configure the Docker service to start on boot:
sudo systemctl enable docker
Install Docker on Ubuntu 14.04
Update your package information and ensure that CA certificates are installed:
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates
Add the new GPG key:
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
Create a Docker repository by creating a file named docker.list in the /etc/apt/sources.list.d/ directory:
sudo nano /etc/apt/sources.list.d/docker.list
Add the following to this file:
deb https://apt.dockerproject.org/repo ubuntu-trusty main
Save and exit the file.
Update APT with the commands:
sudo apt-get update
sudo apt-get purge lxc-docker
sudo apt-cache policy docker-engine
Install Docker:
sudo apt-get install docker-engine
After the installation is complete, start the Docker service:
sudo service docker start
This installation procedure automatically configures Upstart to start Docker on boot.
Install Docker on CentOS 7
Update your system:
sudo yum -y update
Create a Docker repository by creating a file named docker.repo in the /etc/yum.repos.d/ directory:
sudo nano /etc/yum.repos.d/docker.repo
Add the following to this file:
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
Save and exit the file.
Install Docker:
sudo yum install docker-engine
After the installation is complete, start the Docker service:
sudo systemctl start docker.service
Configure the Docker service to start on boot:
sudo systemctl enable docker.service
Web hosting with a personal consultant
Fast and scalable, including a free domain for the first year and email address, trust web hosting from IONOS!
Safely working with Docker without using Sudo
The Docker daemon runs as root, which means that users will need to use sudo to run Docker commands.
To avoid having to use sudo for every Docker command, simply add your user(s) to the docker group with the command:
usermod -aG docker [username]
For example, by adding the user jdoe to the Docker group, this user will no longer have to use sudo for every Docker command. To add the user to the group, use the command:
usermod -aG docker jdoe