0

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?

2
  • 2
    A couple things: 1) "to mimic what I hope to be my production deployment": in production you would not run tailwind:watch because you have no need for live reload; 2) There is a few notes in the Docs regarding the tailwind:watch command when it comes to Docker containers, also included in the Troubleshooting section. Commented Jun 20, 2024 at 17:55
  • Thank you. That (css: bin/rails tailwindcss:watch[always] ) worked perfectly If you'd like to turn that into an answer? My fix involved updating Procfile.dev as well as adding app to my chown'd directories for the rails user in the Dockerfile so that tailwind could write the updates Commented Jun 21, 2024 at 15:18

2 Answers 2

1

I encountered the same problem but solved by adding tty: true to 'web' service

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

1 Comment

Thank you for the response; I think that solution can work. My issue turned out to be a misconfiguration of the rails directory between the Dockerfile.dev and the compose.yaml. I forgot to post my solution below so I've just done that now.
0

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.

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.