2. Container Basics

Container Basics Container Basics

Kubernetes runs your applications in containers. In this chapter, you work with containers directly: you run them and build your own with Docker, and you describe a database with Docker Compose.

What You Learn

By the end of this chapter, you can:

  • run, inspect, stop and remove a container
  • package a Python script as an image with a Dockerfile
  • describe a container, its configuration and its storage in a Compose file
  • start and stop PostgreSQL on your machine and keep its data

Sections

SectionIn the lab
2.1. ContainersRun nginx, then build and run an image with your own Python script
2.2. Docker ComposeStart PostgreSQL from a Compose file and keep its data in a volume

How the Labs Work

  • All commands run with Docker on your machine. You don’t need a Kubernetes cluster until chapter 3.
  • Each lab ends with optional tasks. If you finish early, go ahead with them. The following labs don’t depend on them.
Prerequisites

Docker is set up and verified as described in 1. Setup.