Install Docker on Linux
Check your current Linux version with
uname -r. You should see something like 3.10.[alphanumeric string].x86_64.Debian and Ubuntu
Docker runs on:- Ubuntu Xenial 16.04 LTS
- Ubuntu Wily 15.10
- Ubuntu Trusty 14.04 LTS
- Ubuntu Precise 12.04 LTS
- Debian testing stretch
- Debian 8.0 Jessie
- Debian 7.0 Wheezy (you must enable backports)
Debian Wheezy
If so, you need to enable backports (if not, ignore this section):- Log into the system and open a terminal with
sudoorrootprivileges (or runsudo -ifrom your terminal). - Open
/etc/apt/sources.list.d/backports.listwith your favorite text editor (if the file does not exist, create it). - Remove existing entries.
- Add an entry for backports on Debian Wheezy:
deb http://http.debian.net/debian wheezy-backports main - Update your packages:
apt-get update -y
Ubuntu Precise 12.04
If so, you need to make sure you have the 3.13 kernel version. You must upgrade your kernel:- Open a terminal on your system.
- Update aptitude:
sudo apt-get update -y - Install the additional packages:
sudo apt-get install -y linux-image-generic-lts-trustylinux-headers-generic-lts-trusty - On a graphical Ubuntu environment, you need to additionally run the following:
sudo apt-get install -y xserver-xorg-lts-trusty libgl1-mesa-glx-lts-trusty - Reboot your system:
sudo reboot
Update Aptitude
- Log onto your system with a user with
sudoprivileges. - Open a terminal window.
- Purge the older repositories:
sudo apt-get purge -y lxc-docker* && sudo apt-get -y purge docker.io* - Update your packages, making sure
aptworks withhttpsand the server has CA certificates:sudo apt-get update -y && sudo apt-get install -y apt-transport-https ca-certificates - Get the new GPG key:
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D - Open or create the file
/etc/apt/sources.list.d/docker.listin your favorite text editor (you needsudoorrootfor this). -
Add an entry for your OS
Version Source Ubuntu Precise 12.04 LTS deb https://apt.dockerproject.org/repo ubuntu-precise mainUbuntu Trusty 14.04 LTS deb https://apt.dockerproject.org/repo ubuntu-trusty mainUbuntu Wily 15.10 LTS deb https://apt.dockerproject.org/repo ubuntu-wily mainUbuntu Xenial 16.04 LTS deb https://apt.dockerproject.org/repo ubuntu-xenial mainDebian Wheezy deb https://apt.dockerproject.org/repo debian-wheezy mainDebian Jessie deb https://apt.dockerproject.org/repo debian-jessie mainDebian Stretch/Sid deb https://apt.dockerproject.org/repo debian-stretch main - Save and close the file.
- Update Aptitude again:
sudo apt-get update -y
- Verify Aptitude pulls from the right repository:
sudo apt-cache policy docker-engine
Install Docker
If you use Ubuntu Trusty, Wily, or Xenial, install thelinux-image-extra kernel package:sudo apt-get update -y && sudo apt-get install -y linux-image-extra-$(uname -r)
- Install Docker:
sudo apt-get install docker-engine -y - Start Docker:
sudo service docker start - Verify Docker:
sudo docker run hello-world
The Docker Group
If you prefer, you can set up a docker group to run Docker (instead of root). However, as docker must have sudo access, docker receives the same access as root.- Run the following command to create a Docker group on Ubuntu:
sudo groupadd docker && sudo usermod -aG docker ubuntu -
Log out and back in.
- Run the following command to create a Docker group on Debian:
sudo groupadd docker && sudo gpasswd -a ${USER} docker && sudo service docker restartYou may specify a user instead of
${USER}if you prefer. - Verify a successful Docker installation:
docker run hello-world
Red Hat Enterprise Linux (RHEL) and CentOS
Docker runs on RHEL 7 and CentOS 7.Install Docker
Install with Yum
- Log into your system as a user with
sudoprivileges. - Update your system:
sudo yum update -y. - Add the yum repo (use the code below for both RHEL 7 and CentOS 7):
$ sudo tee /etc/yum.repos.d/docker.repo <<-'EOF' [dockerrepo] name=Docker Repository baseurl=https://yum.dockerproject.org/repo/main/centos/7/ enabled=1 gpgcheck=1 gpgkey=https://yum.dockerproject.org/gpg EOF - Install Docker:
sudo yum install docker-engine -y - Start Docker:
sudo service docker start - Verify Docker:
sudo docker run hello-world
Install with the Docker Installation Script
- Log into your system as a user with
sudoprivileges. - Update your system:
sudo yum update -y - Run Docker’s installation script:
curl -fsSL https://get.docker.com | sh;This script adds the
docker.reporepository and installs Docker. - Start Docker:
sudo service docker start - Verify Docker:
sudo docker run hello-world
The Docker Group
If you prefer, you can set up adocker group to run Docker (instead of root). However, as docker must have sudo access, docker receives the same access as root.- Run the following command to create a Docker group and add your user to the group (replace USERNAME with your username):
sudo groupadd docker && sudo usermod -aG docker USERNAME - Log out and back in.
- Verify Docker works without
sudo:docker run hello-world
Start Docker at Boot
Run one of the following:sudo chkconfig docker onsudo systemctl enable docker
Common Issues
Note: Members in the docker group have root privileges. Hardening Docker is covered in a future tutorial.Ubuntu
Ubuntu Utopic 14.10 and 15.05 exist in Docker’sapt repository without official support. Upgrade to 15.10 or [preferably] 16.04. If you use Ubuntu 12.04, you need to update your kernel.Debian
If you run Debian Wheezy, you need to update the sources with backports.“Cannot connect to the Docker daemon. Is ‘docker daemon’ running on this host?”
If you get this error, you need to unset DOCKER_HOST; rununset DOCKER_HOST to clear the variable.
Comments
Post a Comment