2

I am using nginx-proxy docker image to proxying my other web application. I can run this image using

docker run -d -p 80:80 -e ENABLE_IPV6=true -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy

command. Here -v option is mandatory if I run docker without -v ie

docker run -d -p 80:80 -e ENABLE_IPV6=true jwilder/nginx-proxy

it gives the error:

ERROR: you need to share your Docker host socket with a volume at /tmp/docker.sock
Typically you should run your jwilder/nginx-proxy with: `-v /var/run/docker.sock:/tmp/docker.sock:ro`
See the documentation at http://git.io/vZaGJ
WARNING: /etc/nginx/dhparam/dhparam.pem was not found. A pre-generated dhparam.pem will be used for now while a new one is being generated in the background.  Once the new dhparam.pem is in place, nginx will be reloaded.

Now my question is How can I provide this -v argument when I run this docker container using AWS ECS task definition or service.

Can I provide -v argument in the Dockerfile?

Nitin
  • 2,701
  • 2
  • 30
  • 60

1 Answers1

1

The -v flag is shorthand for a bind mounted volume. Here's the AWS documentation for that. You can also do this in the AWS Management Console by adding a volume to the task def revision, then inside the container definition in the Storage and Logging section, mount that volume to the container.

Bind mounts are not currently supported by AWS Fargate. You will want to stick to ECS with EC2 hosts if you're set on using this nginx-proxy setup. Edit: this is no longer true, bind mounts are currently supported for Fargate (thanks @bobics)

A final caveat, bind mounted volumes only persist for the host on which they are mounted. So if you are running more than one EC2 instances as a host, you would have two divergent bind mounted volumes.

bluescores
  • 4,437
  • 1
  • 20
  • 34
  • 2
    Not sure when this changed, but bind bounds are now supported with Fargate. https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_data_volumes.html "Bind mount host volumes are supported when using either the EC2 or Fargate launch types." – bobics Sep 19 '18 at 23:16
  • 1
    I tried bind mounts on Fargate, and while they work, it doesn't look like they can be persisted. It doesn't allow me to set a sourcePath value in task definition config under volumes -> host. – bobics Sep 20 '18 at 23:24
  • Docker allows to mount the volumes at runtime using `-v` flag, but in ECS we have to define the mount point during container definition. How can I specify volume during `runTask`? – Rash Apr 19 '19 at 23:18