Many of the article explains how to install a particular version of Docker. However, they are often quite old and not applicable (or somehow not working for me)
I would like to install Docker Engine 1.11.0~dev how can I do it?
Desired Version
Docker version 1.11.0-dev, build 79edcc5, experimental
Current Latest Version
Docker version 1.11.2, build b9f10c9
After testing all sort of install steps, I realized the key is the exact version name to install. Here is how I eventually got it installed with the version I want.
Experimental Repo
$ echo "deb [arch=amd64] https://apt.dockerproject.org/repo ubuntu-trusty experimental" | sudo tee -a /etc/apt/sources.list.d/docker.list
$ sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
$ sudo apt-get update
# This is the key step for me to find the exact package names to install
$ apt-cache policy docker-engine
$ sudo apt-get install docker-engine=1.11.0~dev~git20160331.233925.0.4a7bd7e-0~trusty
Sample output of policy
$ apt-cache policy docker-engine
1.12.0~dev~git20160421.173724.0.6f67c13-0~trusty 0
500 https://apt.dockerproject.org/repo/ ubuntu-trusty/experimental amd64 Packages
1.12.0~dev~git20160420.164247.0.3022a43-0~trusty 0
500 https://apt.dockerproject.org/repo/ ubuntu-trusty/experimental amd64 Packages
1.11.0~dev~git20160406.072940.0.bb9b173-0~trusty 0
500 https://apt.dockerproject.org/repo/ ubuntu-trusty/experimental amd64 Packages
1.11.0~dev~git20160405.073835.0.8d31b0f-0~trusty 0
500 https://apt.dockerproject.org/repo/ ubuntu-trusty/experimental amd64 Packages
Main Repo
$ echo "deb [arch=amd64] https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee -a /etc/apt/sources.list.d/docker.list
<... the rest is the same ...>
Related
After following steps 1 - 3 from the official docker engine install steps for Ubuntu (updating apt packages, adding Docker’s official GPG key, and applying the command to set up the repository) I get a problem when installing the plugins for the docker engine:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Based on an answer here, it resolves this issue, however I do not understand this option lsb_release -cs in the add-apt-repository command that was used.
The docker bionic repos can be viewed here.
Based on the repo path and name from that link, would this mean that the following command is correct to add the the most recent stable docker repository?
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu/dists/bionic/stable/binary-amd64/Release"
I'm not fully sure about how this command operates, and how the options are correctly given. It doesn't make sense to me why they haven't included this in the official docker engine install steps.
Based on surmise (unfortunately), and dissecting the official command to set up the repository, this will work:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu `lsb_release -cs` stable"
To summarize, this will solve the docker ce installation problem on Ubuntu 18.04 LTS (Bionic Beaver)
sudo apt 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"
sudo apt update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
1. Issue or feature description
Can not install nvidia-docker2 under Ubuntu18.04
2. Steps to reproduce the issue
$ cat /etc/issue
Ubuntu 18.04.1 LTS \n \l
$ docker --version
Docker version 18.06.1-ce, build e68fc7a
$ sudo apt install nvidia-docker2
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
nvidia-docker2 : Depends: docker-ce (= 5:18.09.0~3-0~ubuntu-bionic) but it is not installable or
docker-ee (= 5:18.09.0~3-0~ubuntu-bionic) but it is not installable
E: Unable to correct problems, you have held broken packages.
$ uname -a
Linux zixia-desktop 4.15.0-42-generic #45-Ubuntu SMP Thu Nov 15 19:32:57 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
The Solution
Remove the default docker.io and install Docker from docker official repository.
The script as the following:
sudo apt-get remove docker docker-engine docker.io
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 apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install docker-ce
sudo apt-get install nvidia-docker2
Related to https://github.com/NVIDIA/nvidia-docker/issues/887
Despite trying both the official installation mechanism using the new apt repo described here, as well as the curl -fsSL https://get.docker.com/ | sh route, I still get E: Unable to locate package docker-engine from APT when I try to apt-get install docker-engine.
My versions are:
$ uname -a
Linux blah 4.5.5-x86_64-linode69 #3 SMP Fri May 20 15:25:13 EDT 2016 x86_64 GNU/Linux
$ lsb_release -c
Codename: jessie
$ cat /etc/debian_version
8.5
$ cat /etc/apt/sources.list
deb http://ftp.uk.debian.org/debian/ stable main contrib non-free
deb-src http://ftp.uk.debian.org/debian/ stable main
deb http://security.debian.org/ stable/updates main
deb-src http://security.debian.org/ stable/updates main
deb http://http.debian.net/debian wheezy-backports main
The only file in my /etc/apt/sources.list.d is docker.list which contains:
deb https://apt.dockerproject.org/repo debian-jessie main
apt-cache policy docker-engine doesn't find it either:
apt-cache policy docker-engine
N: Unable to locate package docker-engine
How might I resolve this?
Edit your sources.list and change the following line from:
deb http://http.debian.net/debian wheezy-backports main
to
deb http://ftp.debian.org/debian jessie-backports main
Update and install docker:
apt-get update
apt-get install docker.io
Edit
To install a specific version of docker-engine download the .deb package from here, e,g the latest one is docker-engine_1.9.1-0~jessie_amd64.deb:
wget https://apt.dockerproject.org/repo/pool/main/d/docker-engine/docker-engine_1.9.1-0~jessie_amd64.deb
sudo apt-get update
dpkg -i docker-engine_1.9.1-0~jessie_amd64.deb
Maybe you will get an error , to fix it run:
apt-get -f install
dpkg -i docker-engine_1.9.1-0~jessie_amd64.deb
Your dpkg architecture is probably using 32bit. You can check this using:
dpkg --print-architecture
Fix it by adding amd64 as a foreign architecture:
dpkg --add-architecture amd64
dpkg --print-foreign-architectures
Update your package lists and check for docker-engine:
apt-get update
apt-cache policy docker-engine
Source: https://wiki.debian.org/Multiarch/HOWTO
Login as root user
$ sudo su
Create this file if it does not exist:
# vi /etc/apt/sources.list.d/backports.list
Add this as content of your backports.list
deb http://http.debian.net/debian jessie-backports main
Now perform your apt-get update
# apt-get update
Install the CA certificates
# apt-get install apt-transport-https ca-certificates
Add the new GPG key
# apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
Now open /etc/apt/sources.list.d/docker.list (or create when it does not exist)
# vi /etc/apt/sources.list.d/docker.list
Add as content:
deb https://apt.dockerproject.org/repo debian-jessie main
Perform again your update:
# apt-get update
Verify that APT is pulling from the right repository.
# apt-cache policy docker-engine
Update again
# sudo apt-get update
Install Docker:
# sudo apt-get install docker-engine
Start the docker daemon.
# sudo service docker start
Verify docker is installed correctly.
# sudo docker run hello-world
Hi guys I faced the same problem and recently found a script automated the docker installation process in debian 8. You could see the snippet here (https://gist.github.com/frgomes/a6f889583860f5b330c06c8b46fa0f42). Credit goes to the original script creator.
I add this on line 4 to removed older versions of Docker if it were existed:
sudo apt-get remove docker docker-engine
and few line on line 7:
sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common -y
Then as superuser:
# chmod +x ./install-docker.sh
# sudo ./install-docker.sh
And you get latest docker instead of v 1.5-1:
# docker --version
Docker version 17.05.0-ce, build 89658be
Adding this for reference for others because it would have saved me 10 minutes if such an answer existed.
I tried installing Docker using ubuntu 14.0LTS virtualbox
sudo apt get install docker
However, when I try running docker it gives me the following error
The program 'docker' is currently not installed. You can install it by typing:
sudo apt-get install docker
Why is ubuntu not seeing docker?
The Ubuntu package docker actually refers to a GUI application, not the beloved DevOps tool we've come out to look for.
The instructions for docker can be followed per instructions on the docker page here: https://docs.docker.com/engine/install/ubuntu/
=== UPDATED (thanks #Scott Stensland) ===
You now run the following install script to get docker:
curl -sSL https://get.docker.com/ | sudo sh
Note: review the script on the website and make sure you have the right link before continuing since you are running this as sudo.
This will run a script that installs docker. Note the last part of the script:
If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:
sudo usermod -aG docker stens
Remember that you will have to log out and back in for this to take effect!
To update Docker run:
sudo apt-get update && sudo apt-get upgrade
For more details on what's going on,
See the docker install documentation or #Scott Stensland's answer below
.
=== UPDATE: For those uncomfortable w/ sudo | sh ===
Some in the comments have mentioned that it a risk to run an arbitrary script as sudo. The above option is a convenience script from docker to make the task simple. However, for those that are security-focused but don't want to read the script you can do the following:
Add Dependencies
sudo apt-get update; \
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
Add docker gpg key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
(Security check, verify key fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
$ sudo apt-key fingerprint 0EBFCD88
pub rsa4096 2017-02-22 [SCEA]
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid [ unknown] Docker Release (CE deb) <docker#docker.com>
sub rsa4096 2017-02-22 [S]
)
Setup Repository
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
Install Docker
sudo apt-get update; \
sudo apt-get install docker-ce docker-ce-cli containerd.io
If you want to verify that it worked run:
sudo docker run hello-world
The following explains why it is named like this:
Why install docker on ubuntu should be `sudo apt-get install docker.io`?
IMPORTANT - ubuntu package docker is something entirely different ( avoid it ) :
issue following to view what if any packages you have mentioning docker
dpkg -l|grep docker
if only match is following then you do NOT have docker installed below is an unrelated package
docker - System tray for KDE3/GNOME2 docklet applications
if you do see above lets remove it since its the wrong docker
sudo apt-get remove docker # remove the wrong docker
if you see something similar to following then you have docker installed
dpkg -l|grep docker
ii docker-ce 5:19.03.13~3-0~ubuntu-focal amd64 Docker: the open-source application container engine
ii docker-ce-cli 5:19.03.13~3-0~ubuntu-focal amd64 Docker CLI: the open-source application container engine
NOTE - ubuntu package docker.io is not getting updates ( obsolete do NOT use )
Instead do this : install the latest version of docker on linux by executing the following:
sudo apt-get install docker-ce
below is yet another way to issue the install command
sudo curl -sSL https://get.docker.com/ | sh
# sudo curl -sSL https://test.docker.com | sh # get dev pipeline version
here is a typical output ( ubuntu 16.04 )
apparmor is enabled in the kernel and apparmor utils were already installed
+ sudo -E sh -c apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
Executing: /tmp/tmp.rAAGu0P85R/gpg.1.sh --keyserver
hkp://ha.pool.sks-keyservers.net:80
--recv-keys
58118E89F3A912897C070ADBF76221572C52609D
gpg: requesting key 2C52609D from hkp server ha.pool.sks-keyservers.net
gpg: key 2C52609D: "Docker Release Tool (releasedocker) <docker#docker.com>" 1 new signature
gpg: Total number processed: 1
gpg: new signatures: 1
+ break
+ sudo -E sh -c apt-key adv -k 58118E89F3A912897C070ADBF76221572C52609D >/dev/null
+ sudo -E sh -c mkdir -p /etc/apt/sources.list.d
+ dpkg --print-architecture
+ sudo -E sh -c echo deb [arch=amd64] https://apt.dockerproject.org/repo ubuntu-xenial main > /etc/apt/sources.list.d/docker.list
+ sudo -E sh -c sleep 3; apt-get update; apt-get install -y -q docker-engine
Hit:1 http://repo.steampowered.com/steam precise InRelease
Hit:2 http://download.virtualbox.org/virtualbox/debian xenial InRelease
Ign:3 http://dl.google.com/linux/chrome/deb stable InRelease
Hit:4 http://dl.google.com/linux/chrome/deb stable Release
Hit:5 http://archive.canonical.com/ubuntu xenial InRelease
Hit:6 http://mirror.cc.columbia.edu/pub/linux/ubuntu/archive xenial InRelease
Hit:7 http://mirror.cc.columbia.edu/pub/linux/ubuntu/archive xenial-updates InRelease
Hit:8 http://ppa.launchpad.net/me-davidsansome/clementine/ubuntu xenial InRelease
Ign:9 http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.2 InRelease
Hit:10 http://mirror.cc.columbia.edu/pub/linux/ubuntu/archive xenial-backports InRelease
Hit:11 http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.2 Release
Hit:12 http://mirror.cc.columbia.edu/pub/linux/ubuntu/archive xenial-security InRelease
Hit:14 http://ppa.launchpad.net/numix/ppa/ubuntu xenial InRelease
Ign:15 http://linux.dropbox.com/ubuntu wily InRelease
Ign:16 http://repo.vivaldi.com/stable/deb stable InRelease
Hit:17 http://repo.vivaldi.com/stable/deb stable Release
Get:18 http://linux.dropbox.com/ubuntu wily Release [6,596 B]
Get:19 https://apt.dockerproject.org/repo ubuntu-xenial InRelease [20.6 kB]
Ign:20 http://packages.amplify.nginx.com/ubuntu xenial InRelease
Hit:22 http://packages.amplify.nginx.com/ubuntu xenial Release
Hit:23 https://deb.opera.com/opera-beta stable InRelease
Hit:26 https://deb.opera.com/opera-developer stable InRelease
Get:28 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages [1,719 B]
Hit:29 https://packagecloud.io/slacktechnologies/slack/debian jessie InRelease
Fetched 28.9 kB in 1s (17.2 kB/s)
Reading package lists... Done
W: http://repo.mongodb.org/apt/debian/dists/wheezy/mongodb-org/3.2/Release.gpg: Signature by key 42F3E95A2C4F08279C4960ADD68FA50FEA312927 uses weak digest algorithm (SHA1)
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
aufs-tools cgroupfs-mount
The following NEW packages will be installed:
aufs-tools cgroupfs-mount docker-engine
0 upgraded, 3 newly installed, 0 to remove and 17 not upgraded.
Need to get 14.6 MB of archives.
After this operation, 73.7 MB of additional disk space will be used.
Get:1 http://mirror.cc.columbia.edu/pub/linux/ubuntu/archive xenial/universe amd64 aufs-tools amd64 1:3.2+20130722-1.1ubuntu1 [92.9 kB]
Get:2 http://mirror.cc.columbia.edu/pub/linux/ubuntu/archive xenial/universe amd64 cgroupfs-mount all 1.2 [4,970 B]
Get:3 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 docker-engine amd64 1.11.2-0~xenial [14.5 MB]
Fetched 14.6 MB in 7s (2,047 kB/s)
Selecting previously unselected package aufs-tools.
(Reading database ... 427978 files and directories currently installed.)
Preparing to unpack .../aufs-tools_1%3a3.2+20130722-1.1ubuntu1_amd64.deb ...
Unpacking aufs-tools (1:3.2+20130722-1.1ubuntu1) ...
Selecting previously unselected package cgroupfs-mount.
Preparing to unpack .../cgroupfs-mount_1.2_all.deb ...
Unpacking cgroupfs-mount (1.2) ...
Selecting previously unselected package docker-engine.
Preparing to unpack .../docker-engine_1.11.2-0~xenial_amd64.deb ...
Unpacking docker-engine (1.11.2-0~xenial) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (229-4ubuntu6) ...
Setting up aufs-tools (1:3.2+20130722-1.1ubuntu1) ...
Setting up cgroupfs-mount (1.2) ...
Setting up docker-engine (1.11.2-0~xenial) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Processing triggers for systemd (229-4ubuntu6) ...
Processing triggers for ureadahead (0.100.0-19) ...
+ sudo -E sh -c docker version
Client:
Version: 1.11.2
API version: 1.23
Go version: go1.5.4
Git commit: b9f10c9
Built: Wed Jun 1 22:00:43 2016
OS/Arch: linux/amd64
Server:
Version: 1.11.2
API version: 1.23
Go version: go1.5.4
Git commit: b9f10c9
Built: Wed Jun 1 22:00:43 2016
OS/Arch: linux/amd64
If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:
sudo usermod -aG docker stens
Remember that you will have to log out and back in for this to take effect!
Here is the underlying detailed install instructions which as you can see comes bundled into above technique ... Above one liner gives you same as :
https://docs.docker.com/engine/installation/linux/ubuntulinux/
Once installed you can see what docker packages were installed by issuing
dpkg -l|grep docker
ii docker-ce 5:19.03.13~3-0~ubuntu-focal amd64 Docker: the open-source application container engine
ii docker-ce-cli 5:19.03.13~3-0~ubuntu-focal amd64 Docker CLI: the open-source application container engine
now Docker updates will get installed going forward when you issue
sudo apt-get update
sudo apt-get upgrade
take a look at
ls -latr /etc/apt/sources.list.d/*docker*
-rw-r--r-- 1 root root 202 Jun 23 10:01 /etc/apt/sources.list.d/docker.list.save
-rw-r--r-- 1 root root 71 Jul 4 11:32 /etc/apt/sources.list.d/docker.list
cat /etc/apt/sources.list.d/docker.list
deb [arch=amd64] https://apt.dockerproject.org/repo ubuntu-xenial main
or more generally
cd /etc/apt
grep -r docker *
sources.list.d/docker.list:deb [arch=amd64] https://download.docker.com/linux/ubuntu focal test
sudo apt-get install docker # DO NOT do this
is a different library on ubuntu.
Use sudo apt-get install docker-ce to install the correct docker.
If you want to install docker in an easy way.
Just type:
$sudo apt install docker.io
And, it will start installing.
And, to check whether its working or not type:
$docker
SET UP THE REPOSITORY
For Ubuntu 14.04/16.04/16.10/17.04:
sudo add-apt-repository "deb [arch=amd64] \
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
For Ubuntu 17.10:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu zesty stable"
Add Docker’s official GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Then install
$ sudo apt-get update && sudo apt-get -y install docker-ce
How to install specific version of Docker(like 1.3.2)?
I am unable to find any documentation in docker official docs.
Referring this link for Ubuntu.
Following instructions install docker version 1.0.1:
$ sudo apt-get update
$ sudo apt-get install docker.io
Also, following instructions install latest version of docker 1.4.1:
$ sudo sh -c "echo deb https://get.docker.com/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
$ sudo apt-get update
$ sudo apt-get install lxc-docker
How can I install specific version like 1.3.2?
I find easier to check available versions with
sudo apt-cache policy docker-engine
and then install the one you want:
sudo apt-get install docker-engine=1.7.1-0~trusty
It consists on simply following the instructions from docker docs https://docs.docker.com/engine/installation/ubuntulinux/, but selecting a particular version
Got the answer from this github issue comment.
Summary of above commit:-
echo deb http://get.docker.com/ubuntu docker main > /etc/apt/sources.list.d/docker.list
apt-key adv --keyserver pgp.mit.edu --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
apt-get update
apt-get install -y lxc-docker-1.3.3
If permission issue then use sudo as:
echo deb http://get.docker.com/ubuntu docker main | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt-key adv --keyserver pgp.mit.edu --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
sudo apt-get update
sudo apt-get install -y lxc-docker-1.3.3
Bonus Tip:
Don't know which version? Then hit Tab after lxc-docker- as:
sudo apt-get install -y lxc-docker-<Hit Tab here>
to see list of available docker versions.
How I did it on my laptop (btw https://get.docker.com/ubuntu/ not available anymore):
$ wget -qO- https://get.docker.com/ | sh # install resources
$ apt-cache showpkg docker-engine # show version which are available
$ apt-get install docker-engine=1.8.2-0~willy # install 1.8.2 version
$ sudo apt-mark hold docker-engine # prevent upgrade on sys upgrade
$ docker version # check installed docker version
Follow below step to install specific version of docker-ce and docker-ce-cli .
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"
sudo apt-get update
Find the specific version of docker-ec and docker-ce-cli . Her in this example i am looking for 19.03
apt-cache policy docker-ce | grep 19
apt-cache policy docker-ce-cli | grep 19
From above command you will get list of docker version , copy respected version.
apt-get install docker-ce=5:19.03.14~3-0~ubuntu-bionic docker-ce-cli=5:19.03.14~3-0~ubuntu-bionic
As Docker Introduces two different flavors (CE and EE) the best and easy way of installing Docker on any system. please run the below command and you do not have to do any thing.
wget -qO- https://get.docker.com/ | sh
if you want to install a specific version of a docker, you can run below command to find what all version of docker is present.
apt-cache madison docker-ce #(for ubuntu)
yum list docker-ce.x86_64 --showduplicates | sort -r #(for centos)
then select the proper version and place it in below command.
wget -qO- https://get.docker.com/ | sed 's/docker-ce/docker-ce=<DOCKER_VERSION/' | sh
Another option is to replace install -y lxc-docker in the script with install -y lxc-docker-<version>.
For example, this will install docker 1.6.2:
RUN wget -qO- https://get.docker.com/ubuntu/ | sed -r 's/^apt-get install -y lxc-docker$/apt-get install -y lxc-docker-1.6.2/g' | sh
wget -qO- https://get.docker.com/ | sed 's/lxc-docker/lxc-docker-1.6.2/' | sh
Replace 1.6.2 with the version you want.
I got version 1.6.2 years old from source on Ubuntu 16.04. This might not translate to other Docker versions:
git clone https://github.com/moby/moby docker
cd docker
git tag -l -- find your tag of interest in this list (e.g. v1.6.2)
git checkout <tag name>
sudo make build
Depending on how old your version is, you might see some errors in this step. If you see sample docker images failing to get pulled in, feel free to comment the associated lines out in the Dockerfile. You might see a lvm2 source related failure. Modify the non-existent link to the source specified here. Specifically, in my case, I had to change make Dockerfile refer to the lvm2 source code at git at git://sourceware.org/git/lvm2.git .
sudo make binary