Docker is a container platform that streamlines software delivery and provides isolation, scalability, and efficiency with less overhead than OS level virtualization.
These instructions are taken directly from the official Docker for Ubuntu page, but I wanted to reiterate those tasks essential for installing the Docker Community Edition on Ubuntu 14.04 and 16.04.
Uninstall older versions
$ sudo apt-get remove docker docker-engine
Install extra packages
In order to use the aufs storage driver, install the following packages.
$ sudo apt-get update $ sudo apt-get install \ linux-image-extra-$(uname -r) \ linux-image-extra-virtual
Setup Docker Repository
$ 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"
Install Docker Community Edition
$ sudo apt-get update $ sudo apt-get install docker-ce
The above command installs the Docker engine and client. If you just want the Docker client, see the section further down.
On Ubuntu 14.04 using upstart, docker logs can be found at “/var/log/upstart/docker.log”.
On Ubuntu 16.04 using systemd, the docker engine logs can be viewed by “journalctl -u docker.service”
$ docker --version Docker version 17.03.0-ce, build 3a232c8 $ sudo docker run hello-world
The docker run command from above should return a message like:
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.
Docker via TCP
By default, the docker daemon listens on a local unix port owned by root (/run/docker.sock) which means your docker client will only work from the installed server and as sudo.
Modify ‘/etc/default/docker’ and modify the options so that TCP is the standard port:
On Ubuntu 16.04 using Systemd, this file is not going to be read, so we have to make its existence known in the “/lib/systemd/system/docker.service” script. Comment out the ExecStart line that exists and replace it as shown below.
EnvironmentFile=-/etc/default/docker ExecStart=/usr/bin/dockerd $DOCKER_OPTS #ExecStart=/usr/bin/dockerd -H fd://
Now make sure the firewall allows this port, and restart the service:
$ sudo ufw allow 2375/tcp # Ubuntu 14.04 $ sudo service docker restart # Ubuntu 16.04 with systemd $ sudo systemctl daemon-reload $ sudo systemctl docker restart
Then use the DOCKER_HOST environment variable to inform the docker client where you wish to connect, and run a quick test of the client.
$ export DOCKER_HOST="tcp://0.0.0.0:2375" $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5c54262d1457 hello-world "/hello" 35 minutes ago Exited (0) 35 minutes ago optimistic_kare
The export statement can be appended to “~/.profile” and sourced to take affect upon every login.
One side-effect of using the TCP port and not the root-owned local unix port, is you no longer need to prefix docker client commands with ‘sudo’. However, you lose the auditability provided by sudo logging the command and parameters (‘/var/log/auth.log’ on Ubuntu).
Docker Client Only
Clearly, if you have a client-only install, then you need to read the above section first because your remote Docker engine needs to be listening, and your client host needs DOCKER_HOST to point to the remote Docker engine. You cannot reach the Docker engine with a unix port.
If you need to install the Docker client only, and not the full Docker engine, then you have to do a manual download of the release archive, and extract the binary as described here.
$ mkdir -p /tmp/download && \ curl -L https://get.docker.com/builds/Linux/x86_64/docker-17.03.1-ce.tgz | tar -xz -C /tmp/download && \ rm -rf /tmp/download/docker/dockerd && \ sudo mv /tmp/download/docker/docker* /usr/local/bin/ && \ rm -rf /tmp/download $ docker --version Docker version 17.03.1-ce, build c6d412e
The exact archive name for your desired version can be pulled from the release list.
If you want to install docker-compose, you can do so with Python’s pip “sudo pip install docker-compose”, but you are going to get an older version. It is better to install the latest release (check for the latest version here).
$ sudo curl -o /usr/local/bin/docker-compose -L "https://github.com/docker/compose/releases/download/1.13.0/docker-compose-$(uname -s)-$(uname -m)" $ sudo chmod +x /usr/local/bin/docker-compose $ docker-compose -v docker-compose version 1.13.0, build 1719ceb