Deep Dive into Docker
Dr. Noman Islam
What are docker images?
Running a container
Docker engine
Runc
Containerd
Benefit of this model
Shim
Responsibilities of shim
Docker Daemon
Docker daemon
Images
What does an image contain?
Registries
Image naming
Layers
Swarm mode
What is swarm?
Services
Enabling swarm mode
Node 1
Join swarm
High availability of swarm managers
Services
Scaling a service
Docker compose
Common use cases
How compose works?
Example
Parts of the application
Quick start
mkdir composetest
cd composetest
flask
redis
app.py
import time
import redis
from flask import Flask
app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)
def get_hit_count():
retries = 5
while True:
try:
return cache.incr('hits')
except redis.exceptions.ConnectionError as exc:
if retries == 0:
raise exc
retries -= 1
time.sleep(0.5)
@app.route('/')
def hello():
count = get_hit_count()
return 'Hello World! I have been seen {} times.\n'.format(count)
Dockerfile
# syntax=docker/dockerfile:1
FROM python:3.10-alpine
WORKDIR /code
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
EXPOSE 5000
COPY . .
CMD ["flask", "run", "--debug"]
Compose file
services:
web:
build: .
ports:
- "8000:5000"
redis:
image: "redis:alpine"
Build and run docker compose
Compose watch
services:
web:
build: .
ports:
- "8000:5000"
develop:
watch:
- action: sync
path: .
target: /code
redis:
image: "redis:alpine"
Run the app with compose watch
Splitting up services
services:
redis:
image: "redis:alpine"
Compose.yaml
include:
- infra.yaml
services:
web:
build: .
ports:
- "8000:5000"
develop:
watch:
- action: sync
path: .
target: /code