What is Docker? Docker is an open-source project that automates the deployment of applications inside software containers. ... Docker containers wrap up a piece of software in a complete filesystem that contains everything it needs to run: code, runtime, system tools, system libraries – anything you can install on a server.
Virtualization A VM is an abstraction of physical hardware. Each VM has a full server hardware stack from virtualized BIOS to virtualized network adapters, storage, and CPU. That stack allows run any OS on your host but it takes some power.
Containers Containers are abstraction in linux kernel, just proces, memory, network, … namespaces. Containers run in same kernel as host - it is not possible use different OS or kernel version, but containers are much more faster than VMs.
Image and Container An image is an inert, immutable, file that's essentially a snapshot of a container. Images are created with the build command, and they'll produce a container when started with run. Images are stored in a Docker registry..
System wide info docker version # print version docker system info # system vide information docker system df # docker disk usage docker system prune # cleanup unused data
Docker Images docker image ls # list all images docker image ls -q # quiet output, just IDs docker image rm # remove image docker image pull # pull from registry docker image push # push to registry docker tag image # add new tag
Docker Run docker run [] # Eg.: docker run hello-world docker run debian:8 cat /etc/os-release docker run debian:9 cat /etc/os-release docker run -ti debian
Common Docker Run Params --name -d - run as daemon -ti - map TTY a STDIN (for bash eg.) -e = - set ENV variable -h - set hostname -u - run command by specific user --rm - remove container after stop
List containers docker ps - list running containers docker ps -a - list all containers docker ps -a -q - list IDs of all containers # Eg.: docker rm -f $(docker ps -a -q)
Docker Exec docker exec -d - run command as daemon -e = - set ENV variable -ti - map TTY a STDIN (for bash eg.) -u - run command by specific user # Eg.: docker exec my-debian ls
Dockerfile Dockerfile is preferred way to create images. Dockerfile defines each layer of image by some command. To make image use command docker build
Dockerfile FROM - define base image MAINTAINER - set maintainers name & email RUN - run command and save as layer COPY - copy file or directory to image layer ADD - instead of copy, archives added by add are extracted
Dockerfile ENV - set ENV variable USER - switch user WORKDIR - change working directory VOLUME - define volume ENTRYPOINT - command, run on container starts CMD - parameters for entrypoint
What is Docker Registry? A service responsible for hosting and distributing images. The default registry is the Docker Hub. GitLab contains Docker Registry from version 8.
Image name format # Official image from Docker Inc on Docker Hub debian # Image in user namespace on Docker Hub ondrejsika/debian # Image on own Docker Registry (reg.istry.cz) reg.istry.cz/debian
What is Docker Compose? Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a Compose file to configure your application's services.
Compose Up Arguments -d - run as daemon --force-recreate - always create new cont. --build - build on every run --no-build - don't build, even images not exist --remove-orphans --abort-on-container-exit
What is Docker Swarm? A native clustering system for Docker. It turns a pool of Docker hosts into a single, virtual host using an API proxy system. It is Docker's first container orchestration project that began in 2014. Combined with Docker Compose, it's a very convenient tool to manage containers.