Abdullah Şamil Güser

Containers Concepts

A container is a unit of software/deployment

Why containers?

VM vs Containers

vm_vs_containers

Virtual Machine Container
Large footprint Lightweight
Slow to boot Quick to start (it does not have to boot)
Ideal for long running tasks Ideal for short lived tasks
  Portable
⛔️ Containers are made of layers

Container Registry

Orchestrator

What is Docker

Docker CLI Cheat Sheet - Management

docker info     # Display system information
docker version  # Display the system's version
docker login    # Log in to a Docker registry 

Docker Desktop

Docker CLI Cheat Sheet - Running Containers

docker pull [imageName]                            # Pull an image from a registry
docker run [imageName]                             # Run containers
docker run -d [imageName]                          # Detached mode
docker run --publish 80:80 --name webserver nginx  # pull and run an nginx server
docker start [containerName]                       # Start stopped containers
docker ps                                          # List running containers
docker ps -a                                       # List running and stopped containers
docker stop [containerName]                        # Stop containers
docker kill [containerName]                        # Kill containers
docker image inspect [imageName]                   # Get image info
docker rm [containerName]                          # remove the container

Docker CLI Cheat Sheet - Limits

docker run --memory="256m" nginx  # Set a maximum memory limit for the container
docker run --cpus=".5" nginx      # Set a maximum CPU limit for the container

Docker CLI Cheat Sheet - Attach Shell

docker run -it nginx -- /bin/bash                           # Attach shell to nginx container
docker run -it -- microsoft/powershell:nanoserver pwsh.exe  # Attach Powershell to a nanoserver container
docker container exec -it [containername] -- bash           # Attach to a running container's bash shell

Docker CLI Cheat Sheet - Cleaning Up

docker rm [containerName]             # Removes stopped containers
docker rm $(docker ps -a -q)          # Removes all stopped containers
docker images                         # Lists images
docker rmi [imageName]                # Deletes the image
docker system prune -a                # Removes all images not in use by any containers

Docker CLI Cheat Sheet - Building

docker build -t [name:tag] .             # Builds an image using a Dockerfile located in the same folder
docker build -t [name:tag] -f [fileName] # Builds an image using a Dockerfile located in a different folder
docker tag [imageName] [name:tag]        # Tag an existing image

Docker CLI Cheat Sheet - Tagging

docker tag => Create a target image
  - name:tag
    - myimage:v1
  - repository/name:tag
    - myacr.azurecr.io/myimage:v1