Data Volumes and Configuration

In the last chapter, we learned how to build and share our own container images. Particular focus was placed on how to build images that are as small as possible by only containing artifacts that are really needed by the containerized application.

In this chapter, we are going to learn how we can work with stateful containers—that is, containers that consume and produce data. We will also learn how to configure our containers at runtime and at image build time, using environment variables and config files.

Here is a list of the topics we're going to discuss:

  • Creating and mounting data volumes
  • Sharing data between containers
  • Using host volumes
  • Defining volumes in images
  • Configuring containers

After working through this chapter, you will be able to do the following:

  • Create, delete, and list data volumes.
  • Mount an existing data volume into a container.
  • Create durable data from within a container using a data volume.
  • Share data between multiple containers using data volumes.
  • Mount any host folder into a container using data volumes.
  • Define the access mode (read/write or read-only) for a container when accessing data in a data volume.
  • Configure environment variables for applications running in a container.
  • Parametrize a Dockerfile by using build arguments.