Rails服务器仍在新打开的Docker容器中运行 [英] Rails server is still running in a new opened docker container
问题描述
我想使用Docker部署我的rails项目。因此,我使用Docker-Compose。但是我收到一条奇怪的错误消息。当运行docker-compose up(包含db-container和postgresql,redis和带有rails的Web容器)时,我得到
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 | =>正在启动Puma
rails服务器-h
web_1 | => Rails 4.2.4应用程序从http://0.0.0.0:3000
web_1开始生产=>运行以获取更多启动选项
web_1 | => Ctrl-C关闭服务器
web_1 |服务器已经在运行。检查/usr/src/app/tmp/pids/server.pid。
web_1 |退出
所以我不明白为什么收到此消息,因为每次运行docker-compose up时,都会启动新容器,而不是先前的容器。即使要删除这些 server.pid
,我也无法删除,因为此容器未运行。
web_1 | => Booting Puma
web_1 | => Rails 4.2.4 application starting in production on http://0.0.0.0:3000
web_1 | => Run
rails 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.
我的docker-compose.yml文件
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
Dockerfile-rails
FROM rails:onbuild
ENV RAILS_ENV=production
我认为我不需要发布所有的Dockerfile
I don't think I need to post all my Dockerfiles
UPD:我自己修复了该问题:我只是删除了所有容器并再次运行 docker-compose up
UPD: I fixed it by myself: i just deleted all my containers and ran the docker-compose up
once again
推荐答案
onbuild映像,因此您的工作目录已安装在容器映像中。这对开发非常有用,因为在编辑代码时会实时更新应用程序,并且例如在运行迁移时会更新主机系统。
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.
这也意味着,每次服务器运行时,主机系统tmp目录将与pid文件一起写入,如果服务器未正确关闭,该目录将保留在该文件中。
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
例如当您在docker-compose下使用工头时,这可能是很痛苦的,因为仅按ctrl + c不会删除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.
这篇关于Rails服务器仍在新打开的Docker容器中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!