4
votes

I have a slightly modified version of the container here:

http://jasonwilder.com/blog/2014/03/25/automated-nginx-reverse-proxy-for-docker/

To run it locally I use:

$ docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock -t jwilder/nginx-proxy

And run my other containers similar to below:

$ docker run -e VIRTUAL_HOST=my-domain.local -t -d my-repo/site-name

I'm having trouble converting this to a Task Definition on ECS.

Task definition

I have two containers:

nginx-reverse-proxy

  • Port mappings: Host 80 Container 80
  • Essential: true
  • Command: /app/docker-entrypoint.sh

static-site

  • Port mappings: Host 5000 Container 5000
  • Essential: false
  • Command: /some-file.sh
  • Env vars: VIRTUAL_HOST static.example.com

I have a cluster with one ECS instance and a server with one task, defined above. This keeps cycling and fails with "STOPPED (Essential container in task exited)".

Now I assume I need to setup volumes but all the examples I can find have a path and a name and I can't see how I can convert this "/var/run/docker.sock:/tmp/docker.sock" into any fields available.

1
Stupid question, but can't this be also accomplished with the ELB/ALB load balancers of AWS? Why use nginx?codepushr
AWS charges a lot for the ELBs. Since you potentially need one for every container you run on ECS, it adds up to hundreds of dollars per month quickly just for ELBs if you have many small services.BjornW
@codepushr and be really happy to hear an answer, because I can't find such feature on ALB, or I'm looking badly for it. Traefik can do this even better than nginxholms
I solved it ! use ha-proxy with environment variables. Here's a solution repository.GNOKOHEAT

1 Answers

5
votes

I'm quite late, but I'm going to answer anyway for people who come across this post in the future.

You have answered yourself. It fails because you are not sharing the Docker socket from the host, which is essential to the nginx proxy image.

Go to your Task Definition and add a new Volume. Name it socket and specify the host path /var/run/docker.sock. Then edit your nginx proxy container and under Mount Points choose socket as a source volume and /tmp/docker.sock as the container path. Mark it as read only for security reasons too. Leave the Command section for this container with the default value.

Deploy your new revision and it should work now.