Install Docker on Windows / WSL Ubuntu

We will run the Docker Engine on Windows 10, and connect to it from WSL Bash as WSL does not fully support Docker yet.

OS requirements

To install Docker CE, you need the 64-bit version of one of these Ubuntu versions:

  • Artful 17.10 (Docker CE 17.11 Edge only)
  • Zesty 17.04
  • Xenial 16.04 (LTS)
  • Trusty 14.04 (LTS)

Uninstall old versions

Older versions of Docker were called docker or docker-engine. If these are installed, uninstall them. The Docker CE package is now called docker-ce.

$ sudo apt-get remove docker docker-engine docker.io

Docker CE now uses the overlay2 storage driver by default, and it is recommended that you use it instead of aufs.

Install using the Docker repository

SET UP THE REPOSITORY

  1. Update the apt package index:
$ sudo apt-get update

2. Install packages to allow apt to use a repository over HTTPS:

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

3. Add Docker’s official GPG key:

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

Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint.

$ 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

4. Use the following command to set up the stable repository. You always need the stable repository, even if you want to install builds from the edge or test repositories as well. To add the edge or test repository, add the word edge or test (or both) after the word stable in the commands below.

Note: The lsb_release -cs sub-command below returns the name of your Ubuntu distribution, such as xenial. Sometimes, in a distribution like Linux Mint, you might have to change $(lsb_release -cs) to your parent Ubuntu distribution. For example, if you are using Linux Mint Rafaela, you could use trusty.

amd64:

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

INSTALL DOCKER CE

  1. Update the apt package index.
    $ sudo apt-get update

2. Install the latest version of Docker CE, or go to the next step to install a specific version. Any existing installation of Docker is replaced.

$ sudo apt-get install docker-ce

4. Verify that Docker CE is installed correctly by running the hello-world image.

$ sudo docker run hello-world

This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits. Got an error:

docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.

You cannot run the Linux Docker daemon in WSL. The Linux kernel emulation done by WSL doesn’t have good enough fidelity to support the Docker daemon. The Docker CLI works fine.

 

Install Docker for Windows

Download Docker for Windows: Stable channel

The current version of Docker for Windows runs on 64bit Windows 10 Pro, Enterprise and Education (1607 Anniversary Update, Build 14393 or later).

The Docker for Windows installer will enable Hyper-V for you, if needed, and restart your machine. After Hyper-V is enabled, VirtualBox will no longer work, but any VirtualBox VM images will remain. You can check in Windows Task manager->CPU if virtualization is enabled.

Double-click Docker for Windows Installer.exe to run the installer.

Docker will not start automatically. To start it, search for Docker, select the app in the search results, and click it (or hit Return). When the whale in the status bar stays steady, Docker is up-and-running, and accessible from any terminal window.

PS C:\Users\>docker run hello-world
Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the “hello-world” image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Congratulations! You are up and running with Docker for Windows. Run some docker commands in WSL ubuntu:

root@:~# /mnt/c/Program\ Files/Docker/Docker/resources/bin/docker.exe images
Unable to translate current working directory. Using C:\Users\DOCUME~1\MOBAXT~1\home
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest f2a91732366c 3 weeks ago 1.85kB

 

To not have to type entire path to docker.exe add these lines to /root/.bashrc   in WSL ubuntu and relogin:

PATH=”$HOME/bin:$HOME/.local/bin:$PATH”
PATH=”$PATH:/mnt/c/Program\ Files/Docker/Docker/resources/bin”

root@:~# docker.exe images
Unable to translate current working directory. Using C:\Users\DOCUME~1\MOBAXT~1\home
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest f2a91732366c 3 weeks ago 1.85kB

To avoid this warning message create a directory under /mnt/c/Users/userid/docker and cd to that directory and run docker commands:

root@:/mnt/c/Users/userid/docker# docker.exe info

Containers: 3
Running: 0
Paused: 0
Stopped: 3
Images: 1
Server Version: 17.09.1-ce
…….

 

 

 

 

References:

https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/

https://docs.docker.com/docker-for-windows/install/

https://blog.jayway.com/2017/04/19/running-docker-on-bash-on-windows/

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s