Using a dedicated proxy container in front of Rails app container

I’m in the process of dockerizing a Rails app before deploying it to production.

I was able to create a 2 container (db+app) system and now I’m trying to add a proxy container (with Nginx) to run in front of the app to serve static assets.

  • Can not curl docker swarm from remote host
  • crontab not executing on centos7 container
  • Problems while building neo4j mazerunner project
  • Docker automated build Error: Build failed: Dockerfile not found at ./Dockerfile
  • Can't get Docker image after windows installation
  • How to force a docker container in IBM Bluemix to connect a volume?
  • I have created a basic container starting from nginx:1.11-alpine with the config below

    server {
      listen *:80;
      location / {
        proxy_pass http://app:3000;
      }
    } 
    

    I’m now able to point my browser to http://0.0.0.0 and get the root page, however, static assets are (obviously) not served and I don’t know how to proceed.

    Should I copy the static assets from the app container to the proxy container?

    How should I update the Nginx config file?

    My docker-compose.yml looks like

    version: '2'
    
    volumes:
      postgres-data:
        driver: local
    
    services:
    ...
      app:
        build: .
        command: bin/rails server -b 0.0.0.0
        ports:
          - 3000:3000
        links:
          - postgres:db
        depends_on:
          - postgres
      proxy:
        image: nginx:1.11-alpine
        volumes:
          - ./default.conf:/etc/nginx/conf.d/default.conf
        command: nginx -g 'daemon off;'
        ports:
          - 80:80
          - 443:443
        links:
          - app
        depends_on:
          - app
    

    Thanks.

  • How can I customize a yum .repo file in a Dockerfile so it can be used as a source when installing packages?
  • Docker-compose open all ports
  • Is the Docker engine installed on the server or client?
  • docker: SSH access directly into container
  • Stop VM with MongoDB docker image without losing data
  • How to run docker container with -i -t options using TeamCity?
  • One Solution collect form web for “Using a dedicated proxy container in front of Rails app container”

    One option might be to share assets directory from app container to nginx container through shared volume mount and configure nginx to serve those files.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.