What is Docker and How to install on Ubuntu Server 16.04

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.

 

In a way, Docker is a bit like a virtual machine. But unlike a virtual machine, rather than creating a whole virtual operating system, Docker allows applications to use the same Linux kernel as the system that they’re running on and only requires applications be shipped with things not already running on the host computer. This gives a significant performance boost and reduces the size of the application.

 

A container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, settings. Available for both Linux and Windows based apps, containerized software will always run the same, regardless of the environment. Containers isolate software from its surroundings, for example differences between development and staging environments and help reduce conflicts between teams running different software on the same infrastructure.

Set up the docker repository on Ubuntu

$ sudo apt-get update

$ 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”

Check for details on this link

Install Docker CE (Community Edition)

$ sudo apt-get update

$ sudo apt-get install docker-ce docker-compose

 

The docker cli is used when managing individual containers on a docker engine. It is the client command line to access the docker daemon api.

The docker-compose cli can be used to manage a multi-container application. It also moves many of the options you would enter on the docker run cli into the docker-compose.yml file for easier reuse. It works as a front-end “script” on top of the same docker api used by docker, so you can do everything docker-compose does with docker commands and a lot of shell scripting

 

An Example:

Go for https://hub.docker.com/explore/ and choose a repo

For example, let us choose nginx 

Let us create a folder for this ~$ mkdir nginx-test

Then go in the folder ~$ cd nginx-test

Run the pull command

~$ docker pull nginx

After installation is done you can run one instance of the nginx as follows(this is the simplest way):

~$ docker run nginx

 

To print all containers on the machine (active ones)

~$ docker ps 

To print all containers on the machine

~$ docker ps -a

List all images on the machine

~$ docker images 

To remove container

~$ docker rm [contrainer_name]

Run container

~$ docker run [contrainer_name]

Stop container

~$ docker stop [contrainer_name]

Stop all containers

~$ docker stop $(docker ps -a -q)

Remove all containers

~$ docker rm $(docker ps -a -q)

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.