我正在研究需要具备的方案:
1.在主机上运行的nginx
2.在Docker容器中运行的Rails应用
我的最初工作包括将Dockerfile添加到主机上的rails应用程序目录中,如下所示:
ubuntu@ubuntu-xenial:~/rails_docker$ cat Dockerfile
FROM ruby:2.1-onbuild
ENV HOME /home/rails/webapp
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
WORKDIR $HOME
# Install gems
ADD Gemfile* $HOME/
RUN bundle install
# Add the app code
ADD . $HOME
EXPOSE 8080
EXPOSE 5432
由于我已经在主机上安装了Nginx,因此将其配置为查看主机上存在Rails应用程序的目录:
ubuntu@ubuntu-xenial:~$ cat /etc/nginx/sites-available/www.testblog.io.conf
# MANAGED BY PUPPET
server {
listen *:8080;
server_name www.testblog.io;
index index.html index.htm index.php;
access_log /var/log/nginx/www.testblog.io.access.log combined;
error_log /var/log/nginx/www.testblog.io.error.log;
location / {
root /home/ubuntu/rails_docker/public;
index index.html index.htm index.php;
}
passenger_enabled on;
passenger_ruby /usr/local/rvm/wrappers/default/ruby;
}
我能够构建docker镜像,下一个想法是:
1.在运行“rails container”时,将/ home / ubuntu / rails_docker声明为主机卷
2.暴露端口8080:8080和5432:5432
我使用的命令如下:
ubuntu@ubuntu-xenial:~/rails_docker$ docker run -d -p 8080:8080 --name examplerails -v /home/ubuntu/rails_docker:/home/rails/webapp railsapptest
82c8aa45b8c1a405e198a565feabf105d1afcbb1c37f8b7b11bf764395ed8c4e
当我检查日志时:
ubuntu@ubuntu-xenial:~/rails_docker$ docker logs -f examplerails
Switch to inspect mode.
由于某种原因,它进入了irb模式。知道我在做什么错吗?
提前致谢,
巴基尔
最佳答案
您需要在Dockerfile中有一个 CMD 指令。这是启动Docker容器时运行的命令。如果您不指定命令,它将运行您的 FROM 图像使用的任何命令,如果您查看the Ruby docker image,它将显示为“irb”。
您可以在the Docker documentation中阅读有关 CMD 指令以及有关Dockerfile的所有其他信息。
关于ruby-on-rails - 如何在主机上运行Nginx的情况下在Docker容器中运行Rails应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44988980/