Docker is container-based application framework, which wrap of a specific application with all its dependencies in a container. Docker containers can easily to ship to remote location on start there without making entire application setup. This tutorial will help you to install and manage Docker on Ubuntu 17.04, 16.04 LTS & 14.04 LTS operating system.
#1 – Install Requirements
First of all install the required packages for docker installation.
$ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
For standard installation Docker required 64 bit operating system having Kernel >= 3.10 version. Older versions of Kernel have some missing requirements to run all features of Docker.
$ uname -r 4.4.0-21-generic
Ubuntu 14.04 LTS users recommended to install the linux-image-extra kernel package.
$ sudo apt-get install linux-image-extra-$(uname -r)
#2 – Add Docker Apt Repository
Import dockers official GPG key to verify packages signature before installing them with apt-get.
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add
Run the below comamnd to enable the docker official apt-get repository on your system. This will add entry in systems /etc/apt/sources.list file.
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
#3 – Install Docker on Ubuntu
Remove the old packages installed on your system and purge them using below command.
$ sudo apt-get purge docker lxc-docker docker-engine
Now use the following commands to upgrade apt index and install docker engine on your system.
$ sudo apt-get update $ sudo apt-get install docker-ce
After successful installation of Docker ce, the service will start automatically, Use below command to verify service status.
$ sudo systemctl status docker
Use our Docker Tutorial for Beginners to working with Docker.
#4 – Manage Docker Container
Search Docker Images
First of all search Docker container images from Docker hub. For example, below command will search all images with Ubuntu and list as output.
# docker search ubuntu
Download Docker Images
Now download the Docker container with name Ubuntu on your local system using following commands.
# docker pull ubuntu latest: Pulling from library/ubuntu fa5be2806d4c: Pull complete b4af4261cb15: Downloading [==> ] 3.779 MB/70.55 MB 5d358abc5d9c: Download complete 2933d50b9f77: Download complete
Now make sure that above images has been downloaded successfully on your system. Below command list all images.
# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu latest 36248ae4a9ac 7 days ago 188 MB
Launch New Container with Image
Finally launch a Docker container using above downloaded image on your system. Below command will start a new container and provide you access of that container with /bin/bash shell.
# docker run -i -t ubuntu /bin/bash
To exit from docker container type
After existing from Docker container, execute below command to list all running containers.
# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f2582758af13 ubuntu "/bin/bash" 2 hours ago Up 2 hours first_ubuntu
By default Above command will list only running containers. To list all containers (including stopped container) use following command.
# docker ps -a
You can start, stop or attach to any containers with following commands. To start container use following command.
# docker start <CONTAINER_ID>
To stop container use following command.
# docker stop <CONTAINER_ID>
To attach to currently running container use following command.
# docker attach <CONTAINER_ID>