Rails服务器仍在新打开的Docker容器中运行 [英] Rails server is still running in a new opened docker container

查看:83
本文介绍了Rails服务器仍在新打开的Docker容器中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用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
web_1 | => Rails 4.2.4应用程序从http://0.0.0.0:3000
web_1开始生产=>运行
rails服务器-h 以获取更多启动选项
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 | => 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.

我的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆