To share data volumes between containers
within and across hosts in a grid, to preserve containers' data volumes
across containers life-cycles and dynamic placements in a grid, and
to use the automatic data volume provisioning using IBM Spectrum
Scale,
you need to configure data volumes to use.
Procedure
Follow these steps to create, configure,
and use data volumes:
-
Create and mount a data volume that can be accessed from the Docker hosts in a grid.
-
Configure a volume attribute in the
application template to include the container
directory (path inside the container) of the data volume, the host directory (path accessible to the
host) of the data volume, and optionally the access permission type and a name of an environment
variable that is set inside the container and contains the path of the data volume inside the
container.
-
Configure the relevant applications in the container to use the data volume for data storage.
You can configure application instances to use the environment variable
that is specified in the previous step to obtain the path of the data volume inside the container.
For example, here is an application template with data volume defined:
apache:
type: IBM::ASC::DockerContainer
properties:
imagename: tutum/apache-php
registryurl: registry.hub.docker.com
command: /run.sh
cpu:
shares: 1024
set: 0
mem:
mem_limit_mb: 300
ports:
- containerport: 80
hostport: 8001
ip:
user: root
volumes:
- containerpath: /app
hostpath: /opt/web
permissions: ro
volumeenvvarname: DataVolumeEnvVAR_apache
dataUpdate:
type: IBM::ASC::DockerContainer
properties:
imagename: image:v2
registryurl:
command: /run.sh
user: www-data
volumes:
- containerpath: /tmp
hostpath: /opt/web
permissions: rw
volumeenvvarname: DataVolumeEnvVAR_dataUpdate
dockerpod1:
type: IBM::ASC::DockerPod
properties:
sharedproperties:
network:
type: bridge
containers:
- { get_resource: apache }
- { get_resource: dataUpdate }
The Apache container displays web pages from
/opt/web, which is mapped into the container directory
/app. The permission is read-only.
The dataUpdate container updates the web
pages from /opt/web, which is mapped into the container directory
/tmp_new. The permission is read/write.
The dataUpdate container has a
script /command/change.sh that overwrites the data in
/tmp_new, which is accessible via port 8001 on the host that the Apache
container runs on.
When both containers stop, the files in /opt/web
persist the changes that are made from the dataUpdate container.