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

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

问题描述

我想使用 Docker 部署我的 rails 项目.所以我使用 Docker-Compose.但是我收到一条奇怪的错误消息.当运行 docker-compose up(这包含带有 postgresql、redis 和 web 容器的 db-container 和 rails)我得到一个

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 |=>启动 Pumaweb_1 |=>Rails 4.2.4 应用程序在 http://0.0.0.0:3000 上开始生产web_1 |=>运行rails server -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 下使用 foreman 时,这可能会很痛苦,因为仅按 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天全站免登陆