Ref: https://learn.cantrill.io/courses/docker-fundamentals/lectures/44151202 =OR= https://www.youtube.com/watch?v=BKNnQPyqJvc
DEMO: https://learn.cantrill.io/courses/docker-fundamentals/lectures/44151206 =OR= https://www.youtube.com/watch?v=oW97xGNYNkM → GitHub: https://github.com/acantril/docker-fundamentals/blob/main/Working-with-existing-docker-images.md
Docker Images
- 🔧 Immutable, read-only templates
- changing an image implies creating a new image
- Structure: collection of independent file system layers
- Differential layers → each layer contains only the differences from layer below
- ❗ Layers are independent and can be reused
docker pull
only pulls missing layers → avoids unnecessary uploads & downloads
- Image is presented as a single file to the outside, even if inside there's layers
- Docker Images Diagram
Docker Containers
- 🔧 An instance of a Docker image which can run
- Containers add a writable layer to the image template
- Any data changes that happen at runtime are stored in this layer
- image layers remain unaltered during runtime
- This layer implies a performance hit when container runs
- ❗ Writable layer is linked to container's lifecycle
- persists when container is stopped, but not when it's deleted
- The union file system overlaps all layers as a single entity
- all data is tightly coupled with the host → data cannot be easily moved
- Docker Containers Diagram
Additional useful/basic commands
docker inspect <ID>
- show metadata of Docker object
- Docker object can be image, container, volume…
docker run -d <imgID>
- run and detach container from terminal
- without -d flag, terminal is stuck/bound to container until terminated
docker port <contID>
- show NW mapping of the container
docker exec -it <contID> ps -aux
- execute command ps -aux
inside container
docker exec -it <contID> sh
- run a shell inside container