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.

  • Is it possible to run android emulator / android apps in docker?
  • fork/exec ./debug: operation not permitted
  • pycharm can't complete remote interpreter setup for Docker
  • How to connect to a docker container from outside the host (same network) [OSX 10.11]
  • How can i execute commands inside containers during host provision
  • 403 error on PHP files with nginx, PHP-FPM and docker
  • 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.

  • Service host/port undefined, Kubernetes/Google Container Engine
  • docker containers share unix abstract socket or dbus
  • How to configure docker to be able to have internet access via wireless connection?
  • chrome fake audioinput with real audio output?
  • How to check whether python package is installed or not in Docker?
  • How to build archlinux pkgbuild inside docker with gitlab-ci
  • 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.