Data-only containers

Before Docker introduced the top-level volume management feature, the data-only container was the recommended approach to achieve data persistency. It is worth understanding data-only containers because you will find many implementations that are based on data-only containers. The prime responsibility of a data-only container is to preserve the data. Creating a data-only container is very similar to the method illustrated in the Data volume section. In addition, the containers are named explicitly for other containers to mount the data volume using the container's name. Besides, the container's data volumes are accessible from other containers even when the data-only containers are in the stopped state. The data-only containers can be created in two ways, as follows:

  • During the launch of the container by configuring the data volume and the container's name
  • Data volume can also be inscribed with Dockerfile during image-building, and later, the container can be named during the container's launch

In the following example, we are launching a data-only container by configuring the container launch with the -v and --name options of the docker run subcommand, as shown here:

$ sudo docker run --name datavol 
-v /DataMount
busybox:latest /bin/true

Here, the container is launched from the busybox image, which is widely used for its smaller footprint. Here, we choose to execute the /bin/true command because we don't intend to do any operations on the container. Therefore, we named the container datavol using the --name option and created a new /DataMount data volume using the -v option of the docker run subcommand. The /bin/true command exits immediately with the 0 exit status, which in turn will stop the container and continue to be in the stopped state.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset