What is Docker
-
Docker is one of container implementation. Others are Rocket, Drawbridge, LXC.
Docker Inc. is the company that sells the commercial version of Docker. Docker is also available as open source.
Docker Daemon / dockerd? Manages Docker objects(Eg: Images, containers, networks, and volumes). dockerd also communicate with other daemons to manage Docker services.
Docker client / docker? Users interact with docker client.
User
$ docker run -----> [Docker Client] -----> [Docker Daemon/dockerd]
Docker vs Kubernets
Docker | Kubernetes(Container Orchestration system) | |
---|---|---|
What | Platform for building containers | Platform for managing multiple containers |
Use case | Run containers on 1 host | Run containers on cluster of machines, providing scaling, self-healing, and rollback |
Commands | docker run | helm |
Docker Terms
Term | Description |
---|---|
Docker Host | Machine on which the Docker containers run. It can be a virtual machine or a physical machine |
Container Image/Docker Image | This is used to start the container. |
Docker File |
Shell script for creating Docker image/Container image.
|
Docker Registry | Stores docker images. Same as github,gitlab are for source code. Eg: dockerhub, elastic container registry(ecr) |
Docker Volumes
-
This is a persistent storage location managed by Docker, outside the container’s filesystem.
Helpful when you want to store data present in database across container reboots/deletion/recreation.
Volumes are defined in docker-compose.yml and mapped to a path inside the container.
volumes, bind mounts, tmpfs all are seen as mounted directories to container.
Name of docker volume:
Docker Compose auto-generates the volume name as project-name_volume
// Check volumes
> docker volume ls
go-server_db_data
// Delete a volume
> docker volume rm go-server_db_data
go-server_db_data
Docker Mounts, tmpfs
-
Does not persists data across reboots
Docker Networking
-
Connecting Docker Containers with each other and with outside world.
Types of Docker Networking
Network | Description | ||||||
---|---|---|---|---|---|---|---|
Bridge Networking |
Used when multiple containers want to communicate on the same Docker host. Types of Bridges:
Run 2 different Alpine containers on same docker host and commmunicate between them
|
||||||
None Networking |
This completely disables the networking stack on the container. Within the container, only the loopback device is created
Example:
|
||||||
Host Networking |
Container's network stack is same as host network stack. IP Address of container is same as host OS.
Useful in situtation where container needs to listen/read/write on large number of ports. Advantages 1. Expose 1 port and IP access the service. Example: 50 Game servers are running in Docker containers on same host. Requests are routed using kubernets to free game server. Disadvantages: Host networking driver only work on linux not on Windows and MAC. Example: Nginx container binds directly to port 80 on the Docker host: Start ngnix in container with host networking, ngnix listens on port 80 which is same as docker host.
|