How to set up nginx as a reverse proxy for a Ruby application (everything works inside Docker)

I'm trying to set up a simple reverse proxy using nginx and a Ruby app, but I also want to set it up inside Docker containers.

I've gotten to the point where I can run a Ruby app from inside Docker and access the running service from the host machine (my Mac OS X using Boot2Docker). But I'm now stuck trying to implement the nginx part as I haven't used it before and most of the articles / tutorials / examples on the topic use Rails (not a simple Sinatra / Rack application) and also use sockets which I don't need as far as I do known.

I am using Docker Compose as well.

The complete directory structure looks like this:

├── docker-compose.yml
├── front-end
│   ├── Dockerfile
│   ├── Gemfile
│   ├── app.rb
│   ├── config.ru
├── proxy
│   ├── Dockerfile
│   ├── nginx.conf
│   └── public
│       ├── 500.html
│       ├── index.html

      

To view the contents of these files, refer to the following text:

https://gist.github.com/Integralist/5cfd5c884b0f2c0c5d11

But when I run docker-compose up -d

I get the following error:

Creating clientcertauth_frontend_1...
Pulling image ./front-end:latest...
Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.cli.main", line 31, in main
  File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.cli.docopt_command", line 21, in sys_dispatch
  File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.cli.command", line 27, in dispatch
  File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.cli.docopt_command", line 24, in dispatch
  File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.cli.command", line 59, in perform_command
  File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.cli.main", line 445, in up
  File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.project", line 184, in up
  File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.service", line 259, in recreate_containers
  File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/compose.service", line 242, in create_container
  File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/docker.client", line 824, in pull
  File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/docker.auth.auth", line 67, in resolve_repository_name
  File "/Users/ben/fig/build/docker-compose/out00-PYZ.pyz/docker.auth.auth", line 46, in expand_registry_url
docker.errors.DockerException: HTTPS endpoint unresponsive and insecure mode isn't enabled.

      

I'm not sure what is causing this error (a little googling returns https://github.com/docker/compose/issues/563 , but that seems like a separate issue as I can tell?).

I'm also not really sure nginx.conf

if I'm configured correctly if I can get past this error. The config for nginx looks like it should be doing a reverse proxy properly (for example using frontend

as an upstream app server which then should resolve the docker ip for the front-end container -> as you will see I have linked the two containers together, so I expect the front-end app to be set as an alias inside the /etc/hosts

proxy container).

Does anyone know what I might be missing?

Thank.

+3


source to share


1 answer


In your gist, you are using image

as a key instead build

, so docker-compose tries to pull the image from the registry which doesn't work.

Since you are creating these images locally, the syntax for your file docker-compose.yml

should look like this:



frontend:
  build: front-end/
  ports:
    - "8080:5000"

      

+1


source







All Articles