Docker - MateuszMazurkiewicz/coding-and-learning GitHub Wiki

Resources:

Notes:

Basics

Docker - container management software Docker Image - file, comprised of multiple layers, that is used to execute code in Docker Container Docker Container - running instance of Docker Image

VM vs. Docker - VM uses virtualized hardware (using Hypervisor) and guest Operating System on it (heavy), Docker Container virtualizes OS (light and portable)

Docker Hub - repository of Docker Images

Commands

Dockerfile Commands:

  • FROM (define basic image),
  • RUN (run terminal command),
  • WORKDIR (change directory),
  • COPY (copy form local to docker image),
  • EXPOSE (expose port),
  • CMD [...] (command to run in container with docker run or to pass default parameter after ENTRYPOINT)
  • ENTRYPOINT [...] (command to run in container with docker run 'parameters' with parameters from terminal)

Docker Commands:

  • docker build to build image, -t 'image name':version.
  • docker images to list all images.
  • docker run, -it runs container in interactive mode, -p 'port on the Docker host'/'port in the container' maps port between host and container (default TCP), -v 'host directory':'container directory' mounts volumes to keep them on host, -e 'VARIABLE NAME'='value' sets env variable, --name 'name' sets container name
  • docker ps shows running containers
  • docker login -u 'username'
  • docker tag 'image id' 'name:tag'
  • docker push 'name:tag'
  • docker pull 'name:tag'
  • docker inspect 'image id'

Example: link(https://github.com/MateuszMazurkiewicz/coding-and-learning/blob/main/Dockerfile)

Docker-Compose

  • docker-compose - takes multiple containers and makes them run together as an application. Use .yml file to define services and parameters for each service
  • docker-compose up to run all services, -d in detached state
  • docker-compose down to stop services

Example: link(https://github.com/MateuszMazurkiewicz/coding-and-learning/blob/main/docker-compose.yml)