Docker Containerization and commands.

Docker Containerization and commands.

image.png

We are going to answer :-

  1. What is Docker?
  2. What is Docker Container?
  3. How to install Docker and use Docker commands?
  4. How to deploy a Docker Container using Docker commands?

What is Docker?

Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels.

What is Docker Container?

A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings. Container images become containers at runtime and in the case of Docker containers - images become containers when they run on Docker Engine. Available for both Linux and Windows-based applications, containerized software will always run the same, regardless of the infrastructure. Containers isolate software from its environment and ensure that it works uniformly despite differences for instance between development and staging. Docker containers that run on Docker Engine:

  1. Standard: Docker created the industry standard for containers, so they could be portable anywhere
  2. Lightweight: Containers share the machine’s OS system kernel and therefore do not require an OS per application, driving higher server efficiencies and reducing server and licensing costs
  3. Secure: Applications are safer in containers and Docker provides the strongest default isolation capabilities in the industry

How to install Docker and use Docker commands?

$ curl -fsSL download.docker.com/linux/ubuntu/gpg | sudo apt-key add – $ sudo add-apt-repository "deb [arch=amd64] download.docker.com/linux/ubuntu $(lsb_release -cs) stable" $ sudo apt-get update

image.png

$ apt-cache policy docker-ce

image.png

$ sudo apt-get install -y docker-ce

image.png

$ sudo systemctl status docker

image.png

$ docker --version $ sudo usermod -aG docker ${USER} $ su - ${USER} $ sudo usermod -aG docker vagrant $ docker run -it ubuntu $ docker ps $ docker ps -a

image.png

How to deploy a Docker Container using Docker commands?

First log on to the vagrant vm by starting the vm using “vagrant up” and opening its terminal using “vagrant ssh”.

image.png

Now search for a docker image ‘redis’ using the command “docker search redis”.

image.png

Pull the image to the local repository using ‘docker pull redis’.

image.png

Run the image using the command ‘docker run -d redis’.

Run the terminal of the redis image using the command ‘docker run-it redis’. Come out of the terminal using ctrl+c.

image.png

Inspect the redis image using the command ‘docker inspect redis’ or with container id of redis as ‘docker inspect CONT_ID’.

image.png

Run the redis image in background with the name and port specified.

See all the active images using the command ‘docker ps’ and all images (active or not) using ‘docker ps -a’.

Run an ubuntu image bash using the command ‘docker run -it ubuntu bash’.

image.png

Here, now we know what docker is. We also know how to install it and deploy a container.