Virtual Machines have been the golden standard for cloud infra management due to their benefits such as lightweight cost-effectiveness and scalabilities.
Docker Presents just these with even more ease of management
What is a Virtual Machine?
virtual machine ( VM ) is the virtualization/emulation of a computer system. Virtual machines are based on computer architectures and provide the functionality of a physical computer. Their implementations may involve specialized hardware, software, or a combination or in simpler words they are systems within systems each having its own operating system and software in isolation from one another.
Advantages of VM
- Easy maintenance
- Availability
- Rich with resources
- Cloud service providers like AWS, DigitalOcean, Google, Azure etc.
What limitations do VMs have?
- Less efficiency because they access hardware indirectly
- You’ll require more resources as you operate more VMs
- Performance may be low when several virtual machines are operating on the same host
- Portability is restricted
Containers
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, or in simpler words a package of code and its dependencies in self-sustaining independent wrappers that can be executed on any host system irrespective of its configuration.
What is Docker?
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.
Why do we need Docker?
It's often hard to manage and share programs that run on one computer to another as they utilize multiple dependencies/utilize ports or functionalities that are already being used by other functionalities on the system.
Docker offers tools and a platform to manage the container lifecycle.
- The container is the unit that distributes and tests your application
- Deploy your application without a problem on any server
- Containers are great for continuous integration and continuous delivery (CI/CD) workflows
- Lightweight and fast
- The container-based technology from Docker enables extremely portable workloads.
Docker architecture
Dockerfile
A Dockerfile is a text document that contains all the commands a user could call on the command line to create a running code base/software. Using docker build users can automate a build that executes several command-line instructions in succession.
FROM node:14-alpine
RUN mkdir /newapp
WORKDIR /newapp
COPY package.json yarn.lock ./
RUN yarn install
COPY . .
EXPOSE 4002
RUN yarn build
CMD ["yarn", "start"]
Images
A Docker image contains application code, libraries, tools, dependencies, and other files needed to make an application run. It is often based on other images with minor corrections or changes.
Containers
A container is a runnable image instance. The Docker API or CLI may be used to create, start, stop, move, or delete containers. You may attach storage to a container, link it to one or more networks, or even create a new image based on its existing state.
Registry
The Registry is a stateless, highly scalable server-side application that stores and lets you distribute Docker images. The Registry is open-source, under the permissive Apache license.
It's used to
- tightly control where your images are being stored
- fully own your images distribution pipeline
- integrate image storage and distribution tightly into your in-house development workflow
Docker Hub is a public registry that anybody may access, and Docker is set up by default to seek images on Docker Hub. You may even set up your own personal registry.
When you use commands like,
docker pull NAME[:TAG]
docker run NAME[:TAG]
commands, the required images are pulled from your configured registry.
When you use,
docker push NAME[:TAG]
command, your image is pushed to your configured registry.
Engine
Docker Engine is an open-source containerization engine that may be used to develop and containerize applications.
Docker cheat sheet
List images
docker image ls
List containers
docker container ls
Build from Dockerfile
docker build -t <name> .
Run a container from an image
docker run <tag name>
Delete an image from the local image store
docker image <tag name>
Pull an image from a registry
docker pull <tag name>
Push an image to a registry
docker push <tag name>
Run a container
name the running container “web” and expose port 5000 externally, mapped to port 80 inside the container.
docker container run — name web -p 5000:80 <tag name>
Stop a running container through SIGTERM
docker container stop <tag name>
Stop a running container through SIGKILL
docker container kill <tag name>
List the networks
docker network ls
Delete all running and stopped containers
docker container rm -f $(docker ps -aq)
Print the last 100 lines of a container’s logs
docker container logs — tail 100 <tag name>
Top comments (0)