-
Notifications
You must be signed in to change notification settings - Fork 15
How to set up docker on Ubuntu
Docker works only on 64-bit Linux installation and requires version 3.10 or higher of the Linux Kernel. Check before starting
$ uname -r
4.4.0-53-generic
$ uname -a
Linux ip-172-31-19-132 4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
-
Update apt and ensure APT works with https method and CA certificates are installed
$ sudo apt-get update $ sudo apt-get install apt-transport-https ca-certificates
-
Add the new
GPG
key$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
-
Check your Ubuntu version
$ lsb_release -r
-
Create a docker.list file and add an entry for your OS (substitute the placeholder check the Repository list)
$ sudo vi /etc/apt/sources.list.d/docker.list $ echo "<REPO>" | sudo tee /etc/apt/sources.list.d/docker.list
-
Update
APT
index$ sudo apt-get update
-
Check if
APT
is pulling from the Docker repository. Each entry should have the URLhttps://apt.dockerproject.org/repo/
$ sudo apt-cache policy docker-engine
-
Purge the old repo if it exists
$ sudo apt-get purge lxc-docker
-
Install recommended prerequisites for the OS
$ sudo apt-get install linux-image-extra-$(uname -r) install linux-image-extra-virtual
-
Install docker engine
$ sudo apt-get install docker-engine
-
Start Docker
$ sudo service docker start
-
Run a sample container
$ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world c04b14da8d14: Pull complete Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9 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. 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 Share images, automate workflows, and more with a free Docker Hub account: https://hub.docker.com For more examples and ideas, visit: https://docs.docker.com/engine/userguide/
-
Stop Docker
$ sudo service docker stop
-
Check the service status to be sure that docker has been stopped
$ sudo service docker status ● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: inactive (dead) since Tue 2016-12-13 14:05:23 UTC; 1min 17s ago Docs: https://docs.docker.com Main PID: 1862 (code=exited, status=0/SUCCESS)
-
Update systemd
$ sudo systemctl enable docker
-
Reboot and verify that docker is running
-
Create
docker
group$ sudo groupadd docker
-
Add your user to the
docker
group.$ sudo usermod -aG docker $USER
-
Log out and log back in to re-evaluat your group membership.
-
Verify that you can
docker
commands without sudo -
Run a sample container
$ docker run hello-world
Warning: The docker group is equivalent to the root user. For details on how this impacts security in your system, see Docker Daemon Attack Surface for details.
-
Download the code from the Git repository
$ sudo curl -o /usr/local/bin/docker-compose -L "https://github.com/docker/compose/releases/download/1.9.0/docker-compose-$(uname -s)-$(uname -m)"
-
Apply executable permissions to the binary
$ sudo chmod +x /usr/local/bin/docker-compose
-
Verify the installation
$ docker-compose --version docker-compose version 1.9.0, build 2585387
-
Verify that
bash-completion
is already installed$ sudo apt-cache policy bash-completion
-
Download the completion script
$ sudo curl -L https://raw.githubusercontent.com/docker/compose/$(docker-compose version --short)/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose
-
Log out and log back in
-
Verify that set up keying
docker
and then pressingTAB
$ docker docker docker-containerd-ctr docker-proxy docker-compose docker-containerd-shim docker-runc docker-containerd dockerd