Docker Container Management
In-depth look at Docker container management, covering running containers in the background, monitoring, connecting terminals, and resource allocation. Explore how to enter running containers, manage logs, events, and more. Dive into the world of Docker containers and enhance your skills in operating and optimizing containerized environments.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Docker Container Management Marion Sudvarg, Chris Gill CSE 522S Advanced Operating Systems Washington University in St. Louis St. Louis, MO 63130 1
Last Time Introduced Docker Explained Docker s modular architecture Demonstrated basic image construction Ran interactive containers (containers launched as an interactive shell) CSE 522S Advanced Operating Systems 2
Containers as Services Docker containers are great for encapsulating background services Web applications Databases Logging server Etc. How can we run a Docker container in the background (without attaching it to a shell)? How can we monitor that container? How can we connect a terminal to it for management? How can we allocate and constrain container resource usage? CSE 522S Advanced Operating Systems 3
Running a Container in the Background You can run a container in the background (detached from the terminal) with d: docker run d mycontainer:v0 Useful for non-interactive services View running containers with docker ps Stop a container: docker stop <container>: sends SIGTERM docker kill <container>: sends SIGKILL Can specify container NAME or ID CSE 522S Advanced Operating Systems 4
Entering a Container What if you need to execute a command inside a running container? For example, launch an interactive shell Use Docker Exec: docker exec it <container> /bin/sh Uses setns() syscall under the hood You can also use the nsenter (namespace enter) utility: 1. 2. 3. Use docker ps to get the container name/ID Use docker inspect to get the container s PID Join with: nsenter --target PID --mount --uts --ipc --net --pid CSE 522S Advanced Operating Systems 5
Logging and Events Container output is logged by default to: /var/lib/docker/containers/ID/ID-json.log Default format is JSON (other log types are supported) View log with: docker logs <ID> Server-wide container events can be monitored with: docker events start, stop, kill, etc. Provides a running stream of events, updated live CSE 522S Advanced Operating Systems 6
Volumes and Storage Containers, by default, do not have persistent storage Bind-mount a directory into a container: docker run v hostdir:containerdir Read-only: hostdir:containerdir:ro Docker can also create named volumes enabling persistent, shared storage among containers Create: docker volume create <name> List: docker volume ls Mount: docker run --mount source=<name>,target=<containerdir> CSE 522S Advanced Operating Systems 7
Resource Constraints Docker allows you to apply resource constraints to containers These are enforced with cgroups Docker Server 20.10 began experimental support for cgroups v2 We use v2 for this class as it will likely be the way of the future Set quotas with docker run Update quotas with docker update CSE 522S Advanced Operating Systems 8
Constraints and Cgroups A resource constraint is provided as a flag + parameter value Constraints, and their corresponding cgroup interface, include: Resource Constraint Flag cgroup v2 Interface Memory limit -m, --memory="" memory.max CPU shares/weight (2-262170) -c, --cpu-shares=0 cpu.weight (1-10000) CPU bandwidth --cpu-quota=0 --cpu-period=0 cpu.max CPU bandwidth --cpus=0.000 cpu.max, period 100000 CPUs in which to allow execution --cpuset-cpus="" cpuset.cpus Real-time CPU bandwidth --cpu-rt-runtime=0 --cpu-rt-period=0 For real-time scheduling classes, not yet supported in cgroups v2 Complete list at: https://docs.docker.com/engine/reference/run/#runtime-constraints-on-resources CSE 522S Advanced Operating Systems 9
Statistics Docker provides a way to view container resource usage statistics: docker stats <container> Reads from cgroup stats interface files Shows the defined memory limit Continuously-updating CSE 522S Advanced Operating Systems 10
Next Week We will introduce network namespaces Discuss container networking and communication Introduce Docker Compose for defining applications composed of multiple containers Demonstrate how network namespaces allow containers to provide network/web services CSE 522S Advanced Operating Systems 11
Todays Studio You will construct an inotify log service container image using separate build and production stages Create a storage volume for the service Launch a container from this image that: Runs in the background Has the storage volume mounted Has its memory constrained It will monitor a given directory, and write inotify events to a log file in the storage volume You will: Launch a terminal in the container View the log file contents Use Docker to constrain its memory usage CSE 522S Advanced Operating Systems 12
Todays Readings No additional required readings Continue to read the Docker documentation assigned last time Pay special attention to the Runtime constraints on resources section of the linked docker run reference (Optional) DKR book: Pages 70-83: A discussion of best-practices for building images to optimize for size and speed Pages 85-110: An overview of container management, storage, resource quotas, etc. Pages 115-130: An overview of container management, inspection, logging, etc. Pages 134-138: An overview of docker stats Pages 141-142: An overview of docker events CSE 522S Advanced Operating Systems 13