In this tutorial I will show you, how to Install and Configure Docker on ubuntu.
Before installing docker , if you want to learn the basics, head over to this article – what is docker?
In this article we will explain how to get started with docker by installing and configuring it on a Ubuntu server. Docker supports almost all Unix and Linux distributions. Getting started with docker is very easy there is no complex configuration for docker.
How to install Docker
Docker package is available in native apt repository. The installation package available in the repository will not be the latest version. If you want to install the latest release of docker, you need to install it from the source. In this post we will explain both repository and source installation.
Installing from apt repository
Follow the instructions give below to install docker from the apt repository.
1. Update the server
sudo apt-get update
2. Install docker.io
sudo apt-get install -y docker.io
3. Verify the installation
sudo docker version
root@linuxmasterswiki:~# docker version
Client version: 1.0.1
Client API version: 1.12
Go version (client): go1.2.1
Git commit (client): 990021a
Server version: 1.0.1
Server API version: 1.12
Go version (server): go1.2.1
Git commit (server): 990021a
Installing the latest docker release
To install the latest docker release just execute the following curl command.
curl -sSL https://get.docker.com/ubuntu/ | sudo sh
Pull a base image
Now we have docker installed on the host. Lets try to pull the latest ubuntu base image from docker hub using the following docker command.
sudo docker pull ubuntu:latest
ubuntu@linuxmasterswiki:~$ sudo docker pull ubuntu:latest
sudo: unable to resolve host linuxmasterswiki
Pulling repository ubuntu
04c5d3b7b065: Pulling image (latest) from ubuntu, endpoint: https://registry-1.d04c5d3b7b065: Download complete
511136ea3c5a: Download complete
c7b7c6419568: Download complete
70c8faa62a44: Download complete
d735006ad9c1: Download complete
Verify the downloaded image using the following docker command. It will list all the downloaded and created images in the local repository.
sudo docker images
Creating a container:
Now we have the latest ubuntu docker image in our host. Lets create an interactive container named “test” from the ubuntu image using the following command.
sudo docker run -i -t –name test ubuntu:latest
The above command will create an interactive container with bash shell. you can try installing some package in that container.
Note: You can also create a container without having an image in the local repository. When you execute “docker run” command, docker will look for the base image in the local repository and if it doesn’t find any, docker will automatically pull down the image from the docker hub.
Type “exit” to exit the container. When you exit , the container will stop. You can view all the stopped and running containers using the following command.
sudo docker ps -a
ubuntu@linuxmasterswiki:~$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7b909941a100 ubuntu:latest /bin/bash 3 minutes ago Exited (0) 6 seconds ago test
By default docker client communicates with the docker daemon using the Unix socket docker.sock. If you want to accept connections from a remote docker client, you need to start the docker daemon on a specific port. Follow the instructions give below to start docker daemon on a specific port.
1. Stop the docker service using the following command.
sudo service docker.io stop
2. Execute the following command to start the docker daemon on port 5000 for client connections from all ip address. If you to establish connection from a particular host, then you can mention that ip address instead of “0.0.0.0”
docker -H tcp://0.0.0.0:5000 -H unix:///var/run/docker.sock -d &
Now you will be able to run docker commands from the host as well as from a remote docker client. To run the docker commands from a remote client, use the following syntax.
docker -H tcp://<ip-address-of-host-running-docker-daemon>:5000 <docker-command>
In this post we have learned to install docker on a Ubuntu workstation, we created a basic container from a docker Ubuntu image. Also we learned how to set up client connections for docker daemon. In next post we will cover more advanced features of Docker.
Was this Tutorial helpful? Help others share on Facebook, Twitter, and Google Plus!