Install Docker on Ubuntu

From Bonus Bits
Jump to: navigation, search

Purpose

This article gives the steps to Docker on Ubuntu from CLI.


Prerequisites

  1. IF on Windows 10
    1. Docker Desktop (Must be Pro of Enterprise, Not Home edition)
    2. HowTo:Install_Ubuntu_BASH_on_Windows_10


All-in-One

sudo apt remove docker docker-engine docker.io containerd runc \
&& sudo apt update \
&& sudo apt install apt-transport-https ca-certificates curl gnupg-agent 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 install docker-ce docker-ce-cli containerd.io


Uninstall Older Versions

sudo apt remove docker docker-engine docker.io containerd runc


Setup Docker Repository

  1. sudo apt update
    
  2. sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
    
  3. Add Dockers official GPG Key
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    
  4. Add Repository for your Arch type, most likely as follows
    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    


Install Docker CE

The Community Edition is the free version.

  1. sudo apt update
    
  2. sudo apt-get install docker-ce docker-ce-cli containerd.io
    


If on Windows Ubuntu Subsystem

Enable Docker Expose

  1. Open Docker Desktop Settings
  2. Browse to General
  3. Select Expose Docker daemon on tcp://localhost:2375

Set Docker Host Environment Variable

  1. Open Ubuntu Shell
  2. echo "export DOCKER_HOST=localhost:2375" >> ~/.bash_profile
    
  3. Source for current shells session
    . ~/.bash_profile
    


Test

sudo docker run hello-world


Troubleshooting

Error

Docker is not running in WSL. So direct commands such as docker image list will return this error. Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Solution

  1. If on Ubuntu subsystem on Windows 10
    1. Make sure Docker for Windows is installed
    2. Make sure Docker for Windows settings Expose Docker daemon on tcp://localhost:2375 is enabled
    3. Make sure Docker is running and/or Restart Docker service with Docker for Windows control panel
  2. Make sure DOCKER_HOST environment variable is set and has the correct port


Related Articles


Sources