Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Using Docker Volume Plugins with Amazon ECS-Optimized AMI

DZone's Guide to

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.

· Cloud Zone ·
Free Resource

Site24x7 - Full stack It Infrastructure Monitoring from the cloud. Sign up for free trial.

Amazon 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

  1. As sudo open the /etc/init.d/docker file in your favorite editor on the ECS container host.
  2. Locate the start() function  and fine the "$unshare" -m -- nohup $exec -d ${OPTIONS} ... line below it.
  3. Remove the following from that line: "$unshare" -m --
  4. The remaining execution should look something like:
    nohup $exec -d ${OPTIONS} ${DOCKER_STORAGE_OPTIONS} &>> $logfile &
  5. 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

Site24x7 - Full stack It Infrastructure Monitoring from the cloud. Sign up for free trial.

Topics:
amazon ecs ,docker ,cloud ,containers

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}