67

I would like to build and run Docker containers on Ubuntu 16.04 LTS. How do I install Docker?

Martin Thoma
  • 18,749
  • 26
  • 70
  • 97

7 Answers7

90

Docker comes in two flavours: The Comunity Edition (CE) and the Enterprise Edition (EE). See this question for the differences. Just take Docker CE if you don't know which to take.

There are two ways of installing it (thank you, Katu and Suor!). The official docker way is a bit more recent.

(A) Official Ubuntu Repositories

$ sudo apt-get install docker.io

In the past this way was discouraged as the docker package was super outdated. The universe sources are fairly recent now.

(B) Official Docker Way

The Ubuntu installation instructions list all you need in detail, but in most cases it boils down to:

(1) Set up the docker repository

sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

(2) Install Docker CE

sudo apt-get update
sudo apt-get install docker-ce

(3) Verify the installation

sudo docker run hello-world

The latest version can be found here. It was 18.06 in November 2018. This version is available in the sources from above, whereas the default Ubuntu package sources only contain Docker 1.5 (source). You can find changes in the docker release notes. Version 1.5 is so old that I could not find out how old it is.

Martin Thoma
  • 18,749
  • 26
  • 70
  • 97
  • How is this better than Ubuntu repo version? – Suor Nov 08 '18 at 05:38
  • 2
    The official Docker sources are way more recent. See my updated comment. – Martin Thoma Nov 08 '18 at 06:20
  • 2
    @MartinThoma in my Ubuntu 16.04 the docker.io package is version 17.03.2 (November 2018) – Katu Nov 08 '18 at 08:48
  • @Katu Are you sure you use the default package sources? https://packages.ubuntu.com/xenial/docker.io says docker.io is in version 1.10 on Ubuntu 16.04 (xenial). edit: Ah, in [universe sources](https://packages.ubuntu.com/xenial-updates/docker.io) there is a newer version! – Martin Thoma Nov 08 '18 at 08:55
  • 1
    Thank you, @Katu and Suor! I've adjusted my answer – Martin Thoma Nov 08 '18 at 09:11
29

To install the Ubuntu repository version

sudo apt install docker.io

Check the version with

docker --version

You may still want to do the post-install steps. Thanks @wisbucky

Katu
  • 3,553
  • 25
  • 42
  • 5
    This works fine in Ubuntu 18.04 LTS as well – AndyGaskell Sep 06 '18 at 12:05
  • 2
    This is now the best way nowadays, since the Ubuntu repos are keeping up with the docker releases. Currently, the Ubuntu `docker.io` package is at `docker 18.06.1`. Ubuntu [`docker.io` package was updated on Sep 27, 2018](http://changelogs.ubuntu.com/changelogs/pool/universe/d/docker.io/docker.io_18.06.1-0ubuntu1~18.04.1/changelog), which is only a month after that [version was released on Aug 21, 2018](https://github.com/docker/docker-ce/releases/tag/v18.06.1-ce). You may still want to do the post-install steps: https://docs.docker.com/install/linux/linux-postinstall/ . – wisbucky Nov 29 '18 at 01:14
  • I wonder who thought it would be a good idea to have all these indistinguishable package names available at the same time: `docker`, `docker-ce`, `docker-engine` and of course `docker.io`... – twall Feb 05 '19 at 17:03
7

Easiest way to install docker on Ubuntu using following command that you can get from the https://get.docker.com/

This script is meant for quick & easy install via:

$ curl -fsSL https://get.docker.com | sh

or

wget -qO- https://get.docker.com/ | sh

For test builds (ie. release candidates):

$ curl -fsSL https://test.docker.com | sh

or

 wget -qO- https://test.docker.com/ | sh

For rc build with experimental feature:

$ curl -fsSL https://experimental.docker.com | sh

or

 wget -qO- https://experimental.docker.com/ | sh
mohit uprim
  • 179
  • 1
  • 2
2

BTW, for Linux Mint (which is based on ubuntu), need to change the release name by hand, after adding the repository.

Sub steps:

  • sudo vi /etc/apt/sources.list.d/additional-repositories.list
  • According to underling ubuntu versions:
    • Ubuntu 16.04
      Change sarah or other name, to xenial.
    • Ubuntu 18.04
      Change tara or other name, to bionic.
Eric
  • 452
  • 7
  • 17
2

To install the community edition, add the GPG key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Add the docker repository

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

sudo apt-get update

To make sure, you're going to install docker from Docker repo,

apt-cache policy docker-ce

Now install docker,

sudo apt-get install -y docker-ce

It would be running by default, but you can check the status

sudo systemctl status docker
Noisy_Botnet
  • 1,599
  • 11
  • 15
1

You can follow below steps to install docker-ce in Ubuntu -

  1. install the dependencies first

    sudo apt install apt-transport-https ca-certificates curl software-properties-common
    
  2. add the GPG key for the official Docker repository to the system:

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    
  3. Add the Docker repository in sources.list.d to APT sources using below command -

    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable edge"
    
  4. verify if you are able to install Docker from Docker repository

    apt-cache policy docker-ce
    
  5. Finally, install Docker CE package with below command

    sudo apt-get install -y docker-ce
    

Voila, you have installed Docker-CE. You can verify installation by checking the version of docker-ce installed

docker --version

For more detailed instructions, follow this tutorial

Thomas
  • 6,143
  • 12
  • 30
  • 36
1

Debian installation.

  1. check your ubuntu code name

lsb_release -a | grep Code

Codename: xenial

  1. check your cpu architecture

lscpu | grep Arch

Architecture:x86_64

Finaly download your debian src. Go to https://download.docker.com/linux/ubuntu/dists/, choose your Ubuntu version, browse to pool/stable/ and choose amd64, armhf, ppc64el, or s390x. Download the .deb file for the Docker version you want to install.

sudo dpkg -i /path/to/package.deb

docker -v

Docker version 18.06.0-ce