work

Docker

Basic commands and concepts

Notes from Udemy course

Containers

A container is the execution process which was created from an image.

  • docker ps -a
  • docker <start|stop> <container>

Stop all containers

  • docker stop $(docker ps -a -q)

Delete all containers

  • docker container rm $(docker ps -a -q)

Images

EXAMPLE: billingapp

Load container from image’s Dockerfile [yml]:

  • docker image ls
  • docker run -p 80:80 -p 8080:8080 --name billingapp

Ports:

  • Angular: 80
  • Backend: 8080

Dockerfile

FROM: base image
RUN: executes command in local env
ENV: variable
ARG ...
ADD...
VOLUME: define the filesystem. The host can share storage with the container thath remains after removing the container.
  • docker build -t <name> --build-arg JAr_FL... . (dot)

Docker-compose [yml]

Independent services, independent images

  • Angular app –> Dockerfile (image)
  • Java app –> Dockerfile (image)

Load billingApp recreating all images [yml]:

  • docker-compose -f stack-billing.yml build --no-cache

Run the containers:

  • docker-compose -f stack-billing.yml up -d --force-recreate

Virtual networks

Delete all networks (run before starting containers):

docker network prune

Concepts

  • Docker CLI: Docker daemon: docker engine Docker API: docker command

Docker container: namespaced processes that are started and managed by the Docker daemon as requested through the docker API.

Docker daemon serves the Docker API using UNIX socket at /var/run/docker.sock