Fundamentals of Docker

guraycintir
2 min readMay 25, 2023

--

Docker is a tool that allows us to automate deployment of sofware applications inside containers running on a host machine. Docker provides an abstraction layer that seperates the application layer from infrastructure layer. Users are able to package their applications with all their dependencies into a standardized unit.

Docker Architecture
Docker vs VM
  1. Basic Docker terms
  • Dockerfile : simple text file that contains list of commands which docker client uses to build Docker image. It automates creation of docker image.
  • Docker image : templates for docker containers. It is source code for a docker container.
  • Docker container : copy of docker images. It is isolated environment that runs on host machine. Multiple containers could be created from same docker image.
  • Docker engine : it is core engine of docker. dockerd is server. docker client and server can run on same host and on different hosts. Clients can communicate with dockerd with rest api calls.
  • Docker registry : it is a repository that stores docker images. It could be public or private.

2. Basic Docker commands

  • docker info : shows information about underlying docker engine.
docker info

Server:
Containers: 2
Running: 0
Paused: 0
Stopped: 2
Images: 1
Server Version: 23.0.5
.......
  • docker pull : downloads docker image from docker registry.
docker pull ubuntu

Using default tag: latest
latest: Pulling from library/ubuntu
dbf6a9befcde: Pull complete
Digest: sha256:dfd64a3b4296d8c9b62aa3309984f8620b98d87e47492599ee20739e8eb54fbf
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
  • docker images : shows docker images downloaded locally.
docker images

REPOSITORY TAG IMAGE ID CREATED SIZE
postgres latest bf700010ce28 3 weeks ago 379MB
ubuntu latest 3b418d7b466a 4 weeks ago 77.8MB
  • docker run : runs a container from a docker image.
docker run ubuntu
  • docker ps : shows running containers.
docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d8977c6f1260 postgres "docker-entrypoint.s…" 3 weeks ago Up 3 minutes 0.0.0.0:5432->5432/tcp postgresqldb
  • docker start : runs container previously created.
docker run postgresql

postgresqldb
  • docker stop : stops a running container.
docker stop postgresql

postgresqldb
  • docker stats : shows resource usages of containers.
docker stats

CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
d8977c6f1260 postgresqldb 0.01% 68.5MiB / 3.734GiB 1.79% 1.46kB / 0B 0B / 0B 6
  • docker image rm / docker rmi: remove one or more containers.
docker rm 123a889b196a

123a889b196a
  • docker rmi : remove docker image locally.
docker rmi hello-world

Untagged: hello-world:latest
Untagged: hello-world@sha256:fc6cf906cbfa013e80938cdf0bb199fbdbb86d6e3e013783e5a766f50f5dbce0
Deleted: sha256:9c7a54a9a43cca047013b82af109fe963fde787f63f9e016fdc3384500c2823d
Deleted: sha256:01bb4fce3eb1b56b05adf99504dafd31907a5aadac736e36b27595c8b92f07f1

--

--