DEV Community

Cover image for Sneaking into Docker 🐳
Sewvandi Promodya Wickramasinghe
Sewvandi Promodya Wickramasinghe

Posted on • Updated on

Sneaking into Docker 🐳

The virtual machine has long been the grab standard for cloud infrastructure because of its many benefits. What if there was a more lightweight, cost-effective, and scalable option to a virtual machine?

Docker 🐳 is just like that.

Alt Text

What is a Virtual Machine?

A virtual machine is a system which acts exactly like a computer. Following the virtualization of the hardware, each virtual machine need its own operating system.

VMs have several advantages

  • On the same computer, multiple OS environments can exist in isolation from one another
  • 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 are a solution to the challenge of getting software to run effectively when it is transferred from one computing environment to another.

Containers are commonly used for web, applications, caching services, and small databases.

Docker is a container-based solution for creating distributed applications.

What is Docker?

Alt Text

Docker is an open platform enabling programs to be developed, shipped and executed. Docker allows you to separate your applications for speedy delivery of software from your infrastructure. With Docker, it's the same way you can manage your infrastructure.

Why do we need Docker?

Sometimes you can't set your app on a friend's computer and can't run several programs on the same port.

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

Alt Text

Dockerfile

A Dockerfile is a text file that contains all of the commands that a user may use to create an image from the command line. Users may establish an automated build using docker build that performs numerous command-line commands in a row.

Here's an example:

FROM node:14-alpine

RUN mkdir /app

WORKDIR /app

COPY package.json yarn.lock ./

RUN yarn install

COPY . .

EXPOSE 4000

RUN yarn build

CMD [ "yarn", "start" ]

Enter fullscreen mode Exit fullscreen mode

Images

An image is a read-only template for building a Docker container. An image is frequently based on another image, with some added modifications.

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

A Docker registry stores Docker images.🐳
Docker Hub is a public registry that anybody may access, and Docker is set up by default to seek for images on Docker Hub. You may even set up your own personal registry.

When you use,

docker pull NAME[:TAG]
Enter fullscreen mode Exit fullscreen mode
docker run NAME[:TAG] 
Enter fullscreen mode Exit fullscreen mode

commands, the required images are pulled from your configured registry.

When you use,

docker push NAME[:TAG] 
Enter fullscreen mode Exit fullscreen mode

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.

A few of key commands to remember

List images

docker image ls
Enter fullscreen mode Exit fullscreen mode

List containers

docker container ls
Enter fullscreen mode Exit fullscreen mode

Build from Dockerfile

docker build -t <name> .
Enter fullscreen mode Exit fullscreen mode

Run a container from image

docker run <tag name>
Enter fullscreen mode Exit fullscreen mode

Alt Text

Top comments (2)

Collapse
 
abhixsh profile image
Abishek Haththakage

really value fully article.

Collapse
 
rizkyrajitha profile image
Rajitha Gunathilake

good read