Docker Flashcards
How to login?
docker login harbor.fleetcomplete.dev -u username -p password
How to fetch an image?
docker pull registry.aquasec.com/console:6.2.21171
How to tag?
docker tag 12345 my.registry/my.image:1
Check logs?
docker logs 12345 –follow
Delete image?
docker rmi gitlab/gitlab-ce:13.12.5-ce.0
Delete container?
docker stop gitlab # first stop the container though
docker rm gitlab # removes the container already running.
.
Running containers shared the kernel with the underlying host OS?
True
Kubernetes vs Docker
K8S is the orchestrator of containerized apps. By default uses Docker as container runtime.
ContainerD
A specialized part of docker that takes care of low level tasks like stopping and starting contianers.
Docker as a technology
= RUNTIME + DAEMON/Engine + Orchestrator/Swarm
Orchestrator.
Daemon(dockerd) = RemoteAPI + Networking + Volumes + Image mgt .. etc
Runtime = containerd(higher level maintains the complete lifecycle of an image) + runc(lower level interfaces with underlying OS)
Responsibel for OS constructs, cgroups and namespaces.
dockerd communicates with containerd over grpc
OCI
Open Cotainer Initiative
Docker Installation
Docker Client
Docker Daemon/Engine
The client talks to daemon via local Unix socket
/var/run/docker.sock
docker client can execute commands through docker.sock on daemon.
Check docker images
docker image ls
Run an image
docker container run -it ubuntu:latest /bin/bash
List containers running
docker container ls
docker container ls -a # list all containers
Attach to a running container
docker container exec gitlab -it /bin/bash
Build a docker image
docker image build -t myimage:123 .
Run an image as a container
docker container run -d –name myweb –publish 8080:8080 myimage:123
-d run in the background
What is runc?
runc is a CLI wrapper for libcotainer that was originally designed to replace the LXC.
What is a dangling image?
Image without any tag.
docker image ls –filter dangling=true
How to check manifest of an image
docker image manifest ubuntu:latest
How to make a container restart automaticaller
docker container run –name neversaydie -it –restart always alpine:latest sh
–restart unless-stopped
Example gitlab volume mount
docker run –detach \
–hostname gitlab.fleetcomplete.com \
–publish 443:443 –publish 23:22 –publish 80:80 \
–name gitlab \
–restart always \
–volume /src/gitlab/config:/etc/gitlab \
–volume /src/gitlab/logs:/var/log/gitlab \
–volume /src/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:fc-latest
docker-compose yaml example
version: "3.8" services: web-frontend: build: . command: python app.py ports: - target: 5000 published: 5000 networks: - counter-net volumes: - type: volume source: counter-volume target: code redis: image: redis:alpine network: - counter-net networks: counter-net: volumes: counter-volume:
List network
docker network ls
List volumes
docker volume ls
Start an app using docker compose
docker-compose -f myapp.yaml up -d
docker-compose -f myapp.yaml down # stops and deletes the containers.
docker-compose restart
docker-compose ps