Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails server is still running in a new opened docker container

I want to deploy my rails project using Docker. So I use Docker-Compose. But I get one weird error message. When run docker-compose up(this contains db-container with postgresql, redis and web container with rails) I get a

web_1 | => Booting Puma web_1 | => Rails 4.2.4 application starting in production on http://0.0.0.0:3000 web_1 | => Runrails server -hfor more startup options web_1 | => Ctrl-C to shutdown server web_1 | A server is already running. Check /usr/src/app/tmp/pids/server.pid. web_1 | Exiting So I cannot understand why do I get this message, because every time I run docker-compose up, new containers start, not the previous. Even if want to delete these server.pid I am not able to do that, because this container isn't running.

my docker-compose.yml file

web:   dockerfile: Dockerfile-rails   build: .   command: bundle exec rails s -p 3000 -b '0.0.0.0'   ports:     - "80:3000"   links:     - redis     - db   environment:     - REDISTOGO_URL=redis://user@redis:6379/  redis:   image: redis  db:   dockerfile: Dockerfile-db   build: .   env_file: .env_db 

Dockerfile-rails

FROM rails:onbuild  ENV RAILS_ENV=production 

I don't think I need to post all my Dockerfiles

UPD: I fixed it by myself: i just deleted all my containers and ran the docker-compose up once again

like image 297
handkock Avatar asked Jan 26 '16 19:01

handkock


People also ask

How do you stop a server is already running in rails?

This normally happens when you stop the server with ctrl+z instead of ctrl+c to exit the Rails server. ctrl+z suspends the process but doesn't close the server running on port 3000 meaning the server is still running on background. This can also happen when you close the terminal that the rails server was running on.

How do I stop a docker container from running?

Note that pressing `Ctrl+C` when the terminal is attached to a container output causes the container to shut down.

How do I stop docker container and start again?

The syntax is simple: $ docker stop [OPTIONS] CONTAINER [CONTAINER...] You can specify one or more containers to stop. The only option for docker stop is -t (–time) which allows you to specify a wait time before stopping a container.

How do you stop the container in detached mode?

To stop this container, press Ctrl+C in the terminal where it was started. Alternatively, you may start a container in detached mode using the -d option. To see all running containers, use the docker ps command.


1 Answers

You are using an onbuild image, so your working direcotry is mounted in the container image. This is very good for developing, since your app is updated in realtime when you edit your code, and your host system gets updated for example when you run a migration.

This also means that your host system tmp directory will be written with the pid file every time a server is running and will remain there if the server is not shut down correctly.

Just run this command from your host system:

sudo rm tmp/pids/server.pid  

This can be a real pain when you are for example using foreman under docker-compose, since just pressing ctrl+c will not remove the pid file.

like image 124
TopperH Avatar answered Sep 20 '22 06:09

TopperH