Using Docker Volume Plugins with Amazon ECS-Optimized AMI
Here are 5 short steps to use volume plugins with Docker while using the Amazon ECS-optimized AMI.
Join the DZone community and get the full member experience.
Join For FreeAmazon EC2 Container Service (ECS) is a highly scalable, high performance container management services that supports Docker containers.
If you want to use volume plugins with Docker and are using the Amazon ECS-optimized AMI
you will need to make some modification in order to successfully mount external volumes within a container.
By default the init.d
script for docker makes mount namespaces unshared in the kernel. Basically mounting and unmounting filesystems will not affect the rest of the system when this is enabled. Volume plugins mount external systems on the container host itself and then automatically associate it to the volume mount target within the container. This is considered sharing
which is why we need to fix the init.d
script in order to use volume plugins.
Fixing the Docker init.d script
- As
sudo
open the/etc/init.d/docker
file in your favorite editor on the ECS container host. - Locate the start() function and fine the
"$unshare" -m -- nohup $exec -d ${OPTIONS} ...
line below it. - Remove the following from that line:
"$unshare" -m --
- The remaining execution should look something like:
nohup $exec -d ${OPTIONS} ${DOCKER_STORAGE_OPTIONS} &>> $logfile &
- Save and restart the docker service
You should now be able to use any volume plugin to mount/unmount external storage within a Docker container.
For more information about volume plugins: https://docs.docker.com/extend/plugins/
To mount NFS, EFS or CIFS volumes in Docker see: https://github.com/gondor/docker-volume-netshare
Published at DZone with permission of Jeremy Unruh, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments