Imprint | Privacy Policy

Containerization

(Usage hints for this presentation)

IT Systems, Summer Term 2024
Dr. Jens Lechtenbörger (License Information)

1. Introduction

1.1. Retrieval Practice

Agenda

2. Containerization

  • Containerization = lightweight virtualization

    Layering with containerization

    • Trade isolation for efficiency (Soltesz et al. 2007)
      • Main idea of containerization: Share kernel among containers
    • Linux mechanisms
      • Kernel namespaces: Limit what is visible inside container
      • Control groups (cgroups): Limit resource usage
      • Own filesystem (chroot), copy-on-write, e.g., UnionFS:
        • New container without copying all files, localized changes

2.1. Terminology

  • Images specify execution environments

    • What OS, what components/programs/dependencies?
      • Dockerfile as build recipe for image

        • Reproducibility

        • E.g. excerpt of Dockerfile for TTS that generates audio in this presentation

          FROM debian:12.1-slim
          RUN apt-get update && apt-get install --no-install-recommends \
           curl ffmpeg git-lfs python3-pip python3-venv unzip -y
          RUN python3 -m venv /tts
          ENV PATH="/tts/bin:$PATH"
          RUN pip install wheel
          COPY tts/requirements* /tts/
          RUN pip install -r /tts/requirements-torch.txt
          RUN pip install -r /tts/requirements.txt
          ...
          
    • Image is template for container

    • Registries publish images

  • Container is process (set), created from image

2.2. Self-Study Question

3. Docker

3.1. Installation

  • Docker Engine (FLOSS, no GUI) is available for different OSs
  • Install on one of your machines, ideally on one that you can bring to (or access in) class
    • Your installation may come with a graphical user interface (GUI), which you do not need
      • Some students perceive the GUI to be confusing
      • Use command line instead to enter commands shown subsequently (any terminal should work, maybe try Bash)

3.2. Basic Commands

  • Start container from image hello-world
    • docker run hello-world

      Unable to find image 'hello-world:latest' locally
      latest: Pulling from library/hello-world
      [...]
      
  • List your images and containers

    • docker image ls
    • docker container ls -all
      • Help is available, e.g.:
        • docker container --help
        • docker container ls --help
  • Maybe delete image and container

    • docker rmi -f hello-world

3.3. Self-Study: A Web Server

  • Run web server nginx

    • Web browsers and servers talk HTTP
    • docker run -p 8080:80 nginx
      • -p: Web server listens on port 80 in container; bind to port 8080 on host
    • Visit http://localhost:8080, nginx server in container

    • Maybe add option --name my-nginx: Assign name to container for subsequent use

      • E.g., docker stop/start/logs/rm my-nginx
  • Serve own web page, e.g., HTML files
    • Add option -v in above docker run ... (before nginx)
      • Mount (make available) directory from host in container
    • E.g.: -v /host-directory/with/html-files:/usr/share/nginx/html
      • /usr/share/nginx/html is where nginx expects HTML files, in particular index.html
      • Thus, your HTML files replace default ones of nginx

3.3.1. Selected Errors

  • Error message: name in use already
    • You cannot use the same name multiple times with docker run --name ...
    • Instead: docker start my-nginx
  • Error message: port is allocated already
    • You cannot use option -p with same port in several docker run invocations
      • Other container still running, stop first
        • docker ps: Note ID or name
        • docker stop <ID-or-name>
        • docker run ...
      • (Or some other process uses that port. Kill process or choose different port.)

3.3.2. On Option -v

  • Say, you start nginx with option -v but your files do not appear
    • docker inspect <name-or-id-of-container>
      • Check output for binds, telling you what is mapped to /usr/share/nginx/html
        • May not meet your expectations
    • Are you on Windows?
      • Try -v C:\Users\... with Powershell
      • Try -v C:\\Users/... with Bash
      • Try -v /mnt/c/Users/... with WSL terminal

4. Conclusions

4.1. Summary

  • Virtual machines are efficient, isolated duplicates of real computer
  • Containers are running processes, defined by images
    • Containers on one host share same OS kernel
    • Isolated as processes, with namespaces and cgroups
  • Virtual machines and containers
    • can be contrasted in terms of their layering approaches
    • allow deploying software in well-defined environments

4.2. Outlook

  • Containerization is enabler of DevOps
    • DevOps = Combination of Development and Operations (Jabbari et al. 2016; Wiedemann et al. 2019)
      • Bridge gaps between teams and responsibilities
      • Aiming for rapid software release cycles with high degree of automation and stability
    • Trend in software engineering
      • Communication and collaboration, continuous integration (CI) and continuous deployment (CD)
      • Approach based on Git also called GitOps (Limoncelli 2018)
        • Self-service IT with proposals in Git pull requests
        • Infrastructure as Code (IaC)

Bibliography

Jabbari, Ramtin, Nauman bin Ali, Kai Petersen, and Binish Tanveer. 2016. “What is DevOps? A Systematic Mapping Study on Definitions and Practices.” In Proceedings of the Scientific Workshop Proceedings of Xp2016. Xp ’16 Workshops. https://doi.org/10.1145/2962695.2962707.
Limoncelli, Thomas A. 2018. “Gitops: A Path to More Self-Service It.” Commun. Acm 61 (9): 38–42. https://doi.org/10.1145/3233241.
Soltesz, Stephen, Herbert Pötzl, Marc E Fiuczynski, Andy Bavier, and Larry Peterson. 2007. “Container-Based Operating System Virtualization: A Scalable, High-Performance Alternative to Hypervisors.” In Acm Sigops Operating Systems Review, 41:275–87. 3. ACM.
Wiedemann, Anna, Nicole Forsgren, Manuel Wiesche, Heiko Gewald, and Helmut Krcmar. 2019. “Research for Practice: The DevOps Phenomenon.” Commun. Acm 62 (8): 44–49. https://doi.org/10.1145/3331138.

License Information

Source files are available on GitLab (check out embedded submodules) under free licenses. Icons of custom controls are by @fontawesome, released under CC BY 4.0.

Except where otherwise noted, the work “Containerization”, © 2019, 2021, 2024 Jens Lechtenbörger, is published under the Creative Commons license CC BY-SA 4.0.