Docker and Docker Compose – Tutorial

What is Docker?

Docker is an open-source platform for deploying, shipping and running an application. And it was first released in 2013.Docker enables you to separate your application from your infrastructure so you can deliver the software quickly and more reliable.

Docker is a set of platforms as a service product that OS level virtualization to delivery software packages called containers. Docker use a client server architecture. The docker clients talk to docker daemon which does they heavy lift of building, running and distributing of docker containers.

Why We Need Docker?

Docker is one of the tools which is used to create, deploy and run the applications by using containers. Docker is a tool which is designed to make it easier to create, deploy, run applications by using containers.

Containers allows a developer to package up all code and all it’s depended. We can do a lot of operations in docker like installed different type of servers like apache and we can install different type of editors like vim editor, GCC editor. And we can do changes over cloud with the help of docker container. We can do Docker compose using docker and docker volumes as well using docker.

Docker provides the ability to package and run an application in a slowly isolated way called container. The isolation and security allow to run many containers simultaneously on a given host. Container are lightweight because they don’t need to extra load of a hypervisor, but run directly within the host machines kernel. In this way we can run more number of containers. We can even run docker containers within host machine that are actually virtual machines.

By Docker

  • We can deploy our application and it’s supporting using containers.
  • The container become the unit for distributing and testing our applications.

Docker Installation on Windows

How to Install Docker on Windows?

Just go to the official website of docker and we can directly download on windows
Link is: https://docs.docker.com/docker-for-windows/install/

After downloading the docker on windows just install it on windows. Before that we all have to create the Docker Hub account. After installing the docker on windows if you open that its ask to login for that we need to the username and password.

(OR)

We can do directly on web cloud. They are a web page of play with docker it’s not for only docker for every tool we do that
Link is: https://labs.play-with-docker.com/

Installing Docker on Windows

Step 1:After visiting the official website of docker i.e.,

https://docs.docker.com/docker-for-windows/install/

Step 2:You will see the official webpage of docker

Step-1 Docker Installation on Windows

Step 3: Click on Download from Docker Hub

Step 4: After clicking on Download from Docker Hub it ill asks weather u want to download for OS, MAC or LINUX.

Step 5: Choosing anyone them.

Step 6:

Step-6 Docker Installation on Windows

Step 7: Click on get docker. It will be starting installation.

Step 8:

Step-8 Docker Desktop Installer

Step 9:

Step 9 Docker Installation on Windows

Docker is successfully installed.
To see whether the docker is running or not
Open Command Prompt and run the docker –version to see the version of Docker

Docker Installation on Windows

Docker Installation on Linux

Step 1:

Docker Installation on Linux Step-1

Step 2:

Docker Installation on Linux Step-2

Step 3:

Docker Installation on Linux Step-3

Step 4:

Docker Installation on Linux Step-4

Step 5:

Docker Installation on Linux Step-5

Step 6:

Docker Installation on Linux Step-6

Step 7:

Docker Installation on Linux Step-7

Docker Installation on Linux Step-8

Container Vs Virtual Machine

Container is standard unit of software that packages up code and all its dependencies so the applications runs quickly and reliable. Container is a runnable instance of an image which we can stop, start, delete, kill and movie using docker API.

Container image become container at run time. And in case of docker container image is become image become container when they run on docker engine. Container is runnable instances of an image. That we can create, delete, run, stop, start, kill the image.

Docker container is an open-source software development platform. It main benefits is to package applications in containers, allowing them to be portable to any system running a LINUX or Windows.

Container vs Virtual Machine

In Virtual Machine

On the bottom of VM we have the hardware on the top of hardware we have the host operating system. On the top of host operating system, we have the hypervisor or virtual box software. On the top of hypervisor, we have the guest OS. But in containers in the place of guest OS there is bare min binders and libs (Bins/Libs). Because whole OS is being installed the size of VM is bigger than container.

Container vs Virtual Machine

Docker Image

What is Docker Image?

Docker image is a set of constructions for creating container. Docker image are lightweight image. A Docker image is an immutable file, which is a snapshot of a container. We can create an image by build command. With the help of docker image we can create the docker container it provides a convenient way to package up applications and preconfigured servers.

A Docker image is a read-only template that contains a set of instructions for creating containers that can run the docker platform. It provides a convenient way to package up applications.

Docker Objects?

When we use docker we can create

  • Docker images
  • Containers
  • Networks
  • Volumes
  • Plugins
  • and other objects

Building an Image: The Dockerfile Basic

To build an image the command is

Docker pull

The pull command is used to pull the image from the cloud.

Dockerfile

Docker file is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build user can create an automated build that executed several command-line instructions.

Example of docker file

FROM ubuntu
Run apt-get-update
Run apt-get-install apache2
ADD. /var/www.html
ENTRYPOINT apachectl-D FORCEDGROUND
ENV name DevOps university

Features of Docker?

Features of docker are:

  • Easy to install and faster configuration
  • Increase productivity
  • Application isolation
  • Docker swarm
  • Routing mesh
  • Services
  • Security management

Docker Compose

Docker compose is basically a tool which can be used with docker to create and configure multiple containers at once with single command. We can do that by writing YML file to configure our application’s servers.

To see the docker compose the command is

Docker-compose –version

By the help of this command, we can see the docker compose version

In docker compose we need to write the YML file in notepad and save in on specific folder after that in terminal go to that file and type the command (docker-compose config) to see the YML file in the terminal. The next step is to do the command is (docker-compose up-d) it is used to pulling the containers after pulling the containers it will start config the containers.

Docker Compose

Here the command docker ps -a is show all the containers that are running.

Docker Compose

Docker Compose and Docker Compose YAML File?

Docker Compose is a tool for defining and running multi-container Docker applications. With Compose.

Docker Compose use a YAML file to configure your application’s services. … Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment. Then with a single command we can create and start all the services from our configuration.

Docker Swarm

Docker is a container orchestration tool part of docker engine. With it developers and IT administrators can deploy and manage a cluster of docker nodes as a single virtual system. Docker swarm allows the users to manage multiple containers deployed across multiple host machine.

Docker swarm is a group of either physical or virtual machine running the docker application and that have been configure to join together in a cluster. Swarm consists of multiple docker hosts which run in swarm mode and act as a manager. Docker works to maintain that desired state. Docker schedules that node’s tasks on another place.

Docker swarm is a new version of docker. It is designed to easily manage containers scheduling over multiple hosts, using docker CLI. It allows to connect multiple hosts with docker together if worker host fails, all containers will be rescheduled to other nodes.

Docker Architecture

Docker use a client server architecture. The docker client talks to docker daemon which does they heavy lifting building, running, and distributing of docker containers.

Docker Architecture

  • A server which is type of long running program is called daemon.
  • A reset API which specifies interface that program use to talk with daemon and instruct what to do.

Docker client and docker daemon run on the same system. Docker client and docker daemon communicate using rest API over network interface.

DOCKER DAEMON: Docker daemon listen to docker API request and manages docker objects such as images, containers, networks, volumes.

DOCKE CLIENT: Docker client is primary way that many docker users interact with docker. The client can communicate with more than one daemon.

DOCKER REGISTER: Docker register stores docker images. Docker hub is public registry that anyone can use, and docker is configured to look for images on docker hub by default.

Docker Architecture

Docker Commands

To login to docker docker login
Before that we need to create the DOCKER HUB account
To build image docker pull <image name>
To see the images docker images
To open the container docker run -it -d <image id>
Here -it is iterative mode and -d is daemon mode
To see whether the container is running or not docker ps (it shows the working container) docker ps -a (it shows all the containers those are present)
To move into some specific containers to do some operations
docker exec -it <image id > bash
Here bash is to move into the ubuntu
To move into some specific containers to do some operations
docker exec -it <image id > bash
Here bash is to move into the ubuntu
After get into the bash update it first apt-get update
To see is there any file in that container Is
If the user wants to install apache2 in the container
apt-get install apache2
To see weather the server is working or not service status apache
If the server is not working service apache2 start
To save the changes in that container docker commit <imageid> new-name
To create any file mkdir<filename>
To open the file cd <filename>

Docker Compose Commands

To see the docker compose version

docker-compose –version

Write the YML file in note pad

Version: ‘3.0’

Services:

ABC:

Image: ubuntu

To see the docker compose version docker-compose –version
To configure the YML file docker-compose config
To build and run our app with compose is docker-compose up -d
To see the container which we gave in the yml file docker ps -a (After this command we are able to see the fie which we gave in the YML file)

0 Comments

Submit a Comment

Your email address will not be published.