3

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.

4
  • Stupid question, but can't this be also accomplished with the ELB/ALB load balancers of AWS? Why use nginx? Commented Jan 18, 2017 at 21:18
  • 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. Commented Apr 19, 2017 at 8:19
  • @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 nginx Commented Feb 4, 2019 at 17:54
  • I solved it ! use ha-proxy with environment variables. Here's a solution repository. Commented Oct 26, 2019 at 9:39

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.