Table of contents
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.
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.
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
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
Installing Docker:
- 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:
Need to add the user to the particular group of the docker to grant access to it
Without installing need to run MySQL.
- 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:
Pull image from docker hub
- 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:
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
How to run/enter the container
To view detailed information about a container or image, you can use the docker inspect command
Eg: To run hello-world