Skip to main content

Install Docker on Linux [Beginners Guide]






Install Docker on Linux

No matter your distribution of choice, you’ll need a 64-bit installation and a kernel at 3.10 or newer. Kernels older than 3.10 do not have the necessary features Docker requires to run containers; data loss and kernel panics occur frequently under certain conditions.
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):
  1. Log into the system and open a terminal with sudo or root privileges (or run sudo -i from your terminal).
  2. Open /etc/apt/sources.list.d/backports.list with your favorite text editor (if the file does not exist, create it).
  3. Remove existing entries.
  4. Add an entry for backports on Debian Wheezy:
     deb http://http.debian.net/debian wheezy-backports main
    
  5. 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:
  1. Open a terminal on your system.
  2. Update aptitude:
     sudo apt-get update -y
    

  3. Install the additional packages:
     
    sudo apt-get install -y linux-image-generic-lts-trusty linux-headers-generic-lts-trusty
    
  4. 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
    
  5. Reboot your system:
     sudo reboot
    

Update Aptitude

  1. Log onto your system with a user with sudo privileges.
  2. Open a terminal window.
  3. Purge the older repositories:
     sudo apt-get purge -y lxc-docker* && sudo apt-get -y purge docker.io*
    

  4. Update your packages, making sure apt works with https and the server has CA certificates:
     sudo apt-get update -y && sudo apt-get install -y apt-transport-https ca-certificates
    
  5. Get the new GPG key:
     sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
    

  6. Open or create the file /etc/apt/sources.list.d/docker.list in your favorite text editor (you need sudo or root for this).
  7. Add an entry for your OS
    Version Source
    Ubuntu Precise 12.04 LTS deb https://apt.dockerproject.org/repo ubuntu-precise main
    Ubuntu Trusty 14.04 LTS deb https://apt.dockerproject.org/repo ubuntu-trusty main
    Ubuntu Wily 15.10 LTS deb https://apt.dockerproject.org/repo ubuntu-wily main
    Ubuntu Xenial 16.04 LTS deb https://apt.dockerproject.org/repo ubuntu-xenial main
    Debian Wheezy deb https://apt.dockerproject.org/repo debian-wheezy main
    Debian Jessie deb https://apt.dockerproject.org/repo debian-jessie main
    Debian Stretch/Sid deb https://apt.dockerproject.org/repo debian-stretch main
  8. Save and close the file.
  9. Update Aptitude again:
     sudo apt-get update -y
    

  10. Verify Aptitude pulls from the right repository:
    sudo apt-cache policy docker-engine
    

Install Docker

If you use Ubuntu Trusty, Wily, or Xenial, install the linux-image-extra kernel package:

sudo apt-get update -y && sudo apt-get install -y linux-image-extra-$(uname -r)
  1. Install Docker:
    sudo apt-get install docker-engine -y
    
  2. Start Docker:
     sudo service docker start
    
  3. 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.
  1. Run the following command to create a Docker group on Ubuntu:
     sudo groupadd docker && sudo usermod -aG docker ubuntu
    
  2. Log out and back in.
  3. Run the following command to create a Docker group on Debian:
     sudo groupadd docker && sudo gpasswd -a ${USER} docker && sudo service docker restart
    
    You may specify a user instead of ${USER} if you prefer.
  4. 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

  1. Log into your system as a user with sudo privileges.
  2. Update your system: sudo yum update -y.
  3. 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
    
  4. Install Docker:
     sudo yum install docker-engine -y
    
  5. Start Docker:
     sudo service docker start
    
  6. Verify Docker:
     sudo docker run hello-world
    

Install with the Docker Installation Script

  1. Log into your system as a user with sudo privileges.
  2. Update your system:
     sudo yum update -y
    
  3. Run Docker’s installation script:
     curl -fsSL https://get.docker.com | sh;
    
    This script adds the docker.repo repository and installs Docker.
  4. Start Docker:
     sudo service docker start
    
  5. 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.
  1. 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
    
  2. Log out and back in.
  3. Verify Docker works without sudo:
     docker run hello-world
    

Start Docker at Boot

Run one of the following:
  • sudo chkconfig docker on
  • sudo 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’s apt 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; run unset DOCKER_HOST to clear the variable.

Comments

Popular posts from this blog

How to Speedup your WordPress site with Amazon CloudFront.

Introduction A WordPress performance is quite excellent . The number of WordPress plugins to handle performance is such evidence. But the easiest way to improve your user experience is to accelerate the entire WordPress website using CloudFront. This will help you not only improve site response time reduces the necessary infrastructure, reducing the load on the Web server, so you can reduce the total cost of the infrastructure works WordPress. CloudFront is actually a site can greatly help your site to respond to unexpected load when gained popularity. Today this post is to clarify the method of providing a reasonable standard configuration on the WordPress website or blog. How does CloudFront help? Amazon CloudFront is to improve the user's experience accessing the Web site in several ways: 1.  Anycast DNS is to ensure that customers are routed to the nearest edge location. 2.  The cached content is available to users at the edge position (i

Linux System : Free Employee Monitoring with Automatic Screenshots

Introduction :   A utomatic screen-shots  of Linux system directly import  on your web server with Linux samba server service and scrot command. 1)  Setup web panel UI on your web server :   Get web panel PHP/HTML code from Github URL: https://github.com/raj412/Employee-Monitoring-for-Linux-System It’s work in Linux server LAMP environment(no need database for this configuration ) Defult login username password is admin/1234. You can change username/passwrod from login.php file in line number #6 Login Page : Dashboard : Screenshot Page : 2)  Samba server configuration on web server : I.  Install Samba on your server where you setup Linux screenshot log system web panel. sudo apt-get update sudo apt-get install samba II.  Set a password for your user in Samba sudo smbpasswd -a <user_name> III.  Share gallery-images folder from you web panel. This is my web panel gallery-images p

How to control high traffic load on Apache servers : optimization performance of APACHE2 & PHP-FPM

Everyone handle high traffic loads  on Apache server. During down-time they forget to check server memory . Apache not used lot of memory  still server not responding. All time we restart Apache service and all things will start working good. I also faced same issue numerous time and all-time  used same solution : Restart Apache. After lots of research and reading found one solution. In this blog you see step-by-step guide to apache2 performance settings. System environment: Intel(R) Xeon(R) CPU 3.10GHz, 4 cores | 8GB RAM Ubuntu 16.04 Apache2 version using mpm_event PHP FPM (5.6,7.1) First,  Calculate process size : Download : python script file “ps_mem.py” from Github Open this and ps_mem.py file upload on you server :  https://github.com/raj412/ps_mem chmod a+x ps_mem.py sudo python ps_mem.py Output like this:  See here : 12 Apache processes, consuming a total of  35.7MiB, so each Apache process is using roughly 3MiB of RAM. The 42 php-fpm process u