# #Day 19 Docker

### Docker

Docker is a software platform that allows you to build, test, and deploy applications quickly. Docker packages software into standardized units called containers that have everything the software needs to run including libraries, system tools, code, and runtime. Using Docker, you can quickly deploy and scale applications into any environment and know your code will run.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682272994737/72b54a21-7ad0-4094-a1fb-493e08daca02.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682273180964/ac603496-cc0e-44eb-949f-04936c0f877e.png align="center")

A developer builds an application and sends it to the tester. But, the environments of development and testing systems are different; thus, the code does not work. There are two solutions to this: Docker and Virtual Machines, but Docker is far better in terms of performance, scaling, and efficiency.  
In this article, we will dive into Docker, its comparison with VMs, and its uses with DevOps.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682273414840/18eff61b-0b80-4951-aba4-bf24ffb68e83.png align="center")

#### **Docker vs. Virtual Machines**

Virtual Machine is an application environment that imitates dedicated hardware by providing an emulation of the computer system. Docker and Vmboth have their set of benefits and uses, but when it comes to running applications in multiple environments, both can be utilized. So which one wins? Let's get into a quick Docker vs. VM comparison.

OS Support: VM requires a lot of memory when installed in an OS, whereas Docker containers occupy less space.

Performance: Running several VMs can affect the performance, whereas, Docker containers are stored in a single Docker engine; thus, they provide better performance.

Boot-up time: VMs have a longer booting time compared to Docker.  
Efficiency: VMs have lower efficiency than Docker.

Scaling: VMs are difficult to scale up, whereas Docker is easy to scale up.

Space allocation: You cannot share data volumes with VMs, but you can share and reuse them among various Docker containers.

Portability: With VMs, you can face compatibility issues while porting across different platforms; Docker is easily portable.  
Docker is a hands-down winner.

What is Hypervisor?

Is a kind of virtual environment that uses os resources.Which runs multiple instances on multiple applications(OS).

Hardware-Hypervisor(VM-ware,Hyper-v)-Virtual machine

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682356648723/7c6331f2-e59f-4f2a-b817-464af15d3142.png align="center")

What is Docker Engine?-Acts on top of Hypervisor which runs multiple containers. Runs multiple instances of the same application. On os -Docker package install become (Docker Engine)-Container and deploy Lightweight images includes only binaries and libraries

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682356629985/95403165-3412-4947-adef-1eee7253dec2.png align="center")

**Installing Docker:**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682272063869/75c2a334-ea9c-4d06-a71f-a87024557d9e.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682274633717/f466ce32-b104-4ae9-a492-fabe7332451f.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682274646707/2d81254d-a3a7-44f0-9614-b3945c358633.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682274720909/272c0844-bbbf-436d-9167-080729b23bd8.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682274811531/bc2b899c-9b38-41dd-9d13-6e80fa55a376.png align="center")

1. docker ps: This command is used to list all running containers. By default, it only shows the container ID, image name, and status. To see more information, such as the ports that are mapped to the container or the command that is running inside it, you can use the -a option. For example:
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682362005388/4bed23e3-b1a5-4963-b971-b9178c4f1fee.png align="center")

Need to add the user to the particular group of the docker to grant access to it

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682362230794/55d28535-9e1a-4521-8c3b-e4603dffb41b.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682362316712/e2328fc0-90f8-4d5a-ade2-4d2866bd9c17.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682362388038/fabcdf97-6e15-4c1a-aa70-a42b3b190184.png align="center")

Without installing need to run MySQL.

1. docker pull: This command is used to download an image from a registry. By default, it pulls the latest version of the image. You can also specify a specific version or tag to download. For example:
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682362588259/84d7e528-05ff-445a-904e-1eb1219edab4.png align="center")

Pull image from docker hub

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682362550920/bc84d84c-3d1c-4bea-bbb9-bd87f0af36a9.png align="center")

1. docker images: This command is used to list all images that are available locally. It shows the image ID, repository, tag, and size. To remove an image, you can use the docker rmi command followed by the image ID or name. For example:
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682362642788/7ebf7528-529d-4f45-988c-9ce7d052073d.png align="center")

docker run: This command is used to create and start a new container. It can also be used to specify the image to use for the container, any ports that need to be exposed, and any environment variables that need to be set. For example, to create a new container based on the Ubuntu image and start a bash shell inside it, you can use the following command:

By running this image to become a container but the initial MySQL asks for a password

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682362991646/92ba4772-ad85-43d1-ad0e-b360b1701bbd.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682363038062/00d4bef8-ef51-48d6-8151-86f0ea7295a9.png align="center")

How to run/enter the container

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682363745942/ce3f9262-0b55-425b-a8c9-f44bc6d26d07.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682364143401/10fd78b2-6bae-41a9-8a92-ceee8d8ff668.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682364171123/9814c196-36bd-4177-8280-01fa82df9daa.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682364195596/cd04f882-42f9-4a6d-bf3c-e85a31c447db.png align="center")

To view detailed information about a container or image, you can use the docker inspect command

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682364389161/ec6285f7-5372-4ffa-8475-6fad2b787779.png align="center")

Eg: To run hello-world

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682364779794/de7438af-5364-4ff3-86dd-41a2f1294aa1.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682364816551/be802981-e9e9-4517-92c3-5fd3a220bc73.png align="center")
