Amazon EC2 Container Service (ECS) is a highly scalable, high performance container management services that supports Docker containers.
If you are wanting 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