ruby-on-railsdockerdocker-composeruby-on-rails-7

Debugging tailwindcss:watch in Procfile.dev in Docker


I am trying to build a development compose.yaml to mimic what I hope to be my production deployment. Currently it looks like the following using bin/dev.

services:
  web:
    build:
      context: ./
      dockerfile: Dockerfile.dev
    command: bash -c "rm -f tmp/pids/server.pid && bin/dev"
    volumes:
      - .:/usr/src/app
    ports:
      - "3000:3000"
    env_file:
      - .env/development/db
      - .env/development/web
  db:
    image: postgres:16
    ports:
      - "5432:5432"
    volumes:
      - pg_data:/var/lib/postgresql/data
    env_file:
      - .env/development/db
  redis:
    image: redis
    volumes:
      - redis_data:/data
volumes:
  pg_data:
  redis_data:

The Procfile.dev looks like:

web: bin/rails server -p 3000 -b 0.0.0.0
css: bin/rails tailwindcss:watch

When I try to start up the web service, I get the following output.

āœ— docker compose up web
[+] Running 1/1
 āœ” Container dbventure-web-1  Recreated                                                                                                                       0.1s
Attaching to web-1
web-1  | Preparing database...
web-1  | 13:27:13 web.1  | started with pid 21
web-1  | 13:27:13 css.1  | started with pid 22
web-1  | 13:27:14 web.1  | => Booting Puma
web-1  | 13:27:14 web.1  | => Rails 7.1.3.4 application starting in development
web-1  | 13:27:14 web.1  | => Run `bin/rails server --help` for more startup options
web-1  | 13:27:14 web.1  | Puma starting in single mode...
web-1  | 13:27:14 web.1  | * Puma version: 6.4.2 (ruby 3.3.1-p55) ("The Eagle of Durango")
web-1  | 13:27:14 web.1  | *  Min threads: 5
web-1  | 13:27:14 web.1  | *  Max threads: 5
web-1  | 13:27:14 web.1  | *  Environment: development
web-1  | 13:27:14 web.1  | *          PID: 21
web-1  | 13:27:14 web.1  | * Listening on http://0.0.0.0:3000
web-1  | 13:27:14 web.1  | Use Ctrl-C to stop
web-1  | 13:27:15 css.1  | exited with code 0
web-1  | 13:27:15 system | sending SIGTERM to all processes
web-1  | 13:27:15 web.1  | - Gracefully stopping, waiting for requests to finish
web-1  | 13:27:15 web.1  | Exiting
web-1  | 13:27:16 web.1  | terminated by SIGTERM
web-1 exited with code 0

If I comment out the web entry in the Procfile.dev (or if I simply call bin/rails tailwindcss:watch in the compose.yaml) it also dies immediately.

Questions: Am I just missing something about how that tailwindcss:watch would work in a Docker container or, alternately, is there a way to debug what's happening behind the scenes that would help me figure out why the SIGTERM is being sent?


Solution

  • The answer was more simple than I thought, WORKDIR /rails in the Dockerfile.devhad to be the same value as the volumes in the compose file.

    Changing the compose.yaml to

    services:
      web:
        . . . 
        volumes:
          - .:/rails
    

    worked.

    Also, per a comment on the question adding css: bin/rails tailwindcss:watch[always] to my Procfile.dev also seemed to be necessary to pick up changes.