Docs: https://docs.docker.com/
Gist from Brad: https://gist.github.com/bradtraversy/89fad226dc058a41b596d586022a9bd3
Beginner Tutorial from Mosh: https://youtu.be/pTFZFxd4hOI
very good ELI5: https://www.reddit.com/r/AskComputerScience/comments/9xktwl/eli5_please_what_is_docker/
- like a virtual machine but structured differently to save RAM and CPU
- Docker is a platform for building, running and shipping applications in a consistent manner, so if your application works on your developing machine, it can run and function the same way on other machines.
- A Container is an isolated environment for running an application.
- allows running multiple apps in isolation
- are lightweight
- use / share the OS of the host (every OS needs to be licensed, patched and monitored)
- start quickly
- need less hardware resources
- A virtual machine is an abstract of a machine (or physical hardware).
- For this we need a Hypervisor: a tool to create and manage virtual machines.
- Examples are VirtualBox, VMware (which are both cross-platform (running on Mac, Linux and Windows)) and Hyper-v (Windows only)
- Problems
- each VM needs a full-blown OS (that needs to be licensed, patched and monitored)
- slow to start (because entire OS has to be loaded)
- resource intensive (CPU, Memory, Disk Space)
- a client component talks to a server component via Restful API
- the server component is here called Docker Engine
- technically a container is a process, but a special kind of process with its own file system (which is provided by the image)
- on a Linux machine we can run Linux containers
- on a Windows machine we can now both run Windows and Linux containers, because since Windows10 they added a custom built Linux kernel
- Docker on Mac uses a lightweight VM to run Linux containers
- Mac doesn't have native support for continuous applications
- A dockerfile is a plaintext file that includes instructions that docker uses to package up this application into an image. This image contains everything our application needs to run.
An image contains everything an application needs to run.
- a cut-down OS
- a runtime environment (eg Node)
- application files
- third-party libraries
- environment variables
docker version
docker info
docker ps // show all (running) processes
- show all processes, including stopped ones:
docker ps -a// show (-a) all (ps) processes
docker container ls
- In empty folder create 'docker-compose.yml'
docker-compose up -d
(use docker-compose up without the -d to see what is happening (and know when it has finished))
docker-compose down
docker-compose ps -a
Example for docker-compose.yml:
version: '3.7'
services:
ghost:
image: ghost:latest
restart: always
depends_on:
- db
environment:
url: http://localhost:3001
database__client: mysql
database__connection__host: db
database__connection__user: root
database__connection__password: MyStrongPassword
database__connection__database: ghost
ports:
- 3001:2368
volumes:
- ./content:/var/lib/ghost/content
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: MyStrongPasswordDocker is like a virtual machine but structured differently to save RAM and CPU.
(Create instance from image)
Beispiel: docker run -d --name some-ghost -e url=http://localhost:3001 -p 3001:2368 ghost
Übersetzt: starte docker, (-d for 'detached') lass es im Hintergrund laufen, (--name) nenne es 'some-ghost', (-e) set environment variable: url=...., (-p) Portweiterleitung auf 3001 (von 2368), aus dem image 'ghost'
docker ps -a
docker stop example-container-name
docker system prune -af
https://hub.docker.com/_/ghost/
docker
and
docker run --help
(nach brew update): brew install --cask docker
you do it automatically when you start a container:
docker run -d --name some-ghost -e url=http://localhost:3001 -p 3001:2368 ghost // last part calls the respective image down from docker hub
or you can do it directly:
docker pull nginx
docker image rm exampleID // instead of exampleID use the first 3 digits of the image ID. To get the image ID: list all images (see below)
docker images or
docker image ls
docker container rm example /instead of example use the first 3 digits from the containers ID
to see all containers run:
docker container ls -a