[英]What is the proper way to update the Ruby bin folder for a docker container?
I've been play around with converting an existing Ruby on Rails application to be developed in a docker container. 我一直在努力将现有的Ruby on Rails应用程序转换为在docker容器中开发。 I don't understand where best to incorporate the rake rails:update:bin
command. 我不明白最好合并rake rails:update:bin
命令。 I tried to put it as the last line of the dockerfile but the container won't start up properly. 我试图将它作为dockerfile的最后一行,但容器将无法正常启动。 The only way I can get the container to start up is to build the bin outside of the image construction, so that the bin folder is pulled in with an ADD command. 我可以启动容器的唯一方法是在图像构造之外构建bin,以便使用ADD命令拉入bin文件夹。
Is it possible to create a dockerfile that does all the things? 是否可以创建一个可以完成所有事情的dockerfile?
The Docker file looks like this Docker文件看起来像这样
FROM ruby:2.2
RUN apt-get update && apt-get install -y \
build-essential \
libpq-dev \
nodejs
RUN mkdir /MyApp
WORKDIR /MyApp
ADD Gemfile /MyApp/Gemfile
ADD Gemfile.lock /MyApp/Gemfile.lock
RUN bundle install
ADD . /MyApp
I want to add the following line to the end. 我想在最后添加以下行。
RUN rake rails:update:bin
When I try including the rake
command I'm rebuilding the image without the bin
folder in the MyApp
folder. 当我尝试包含rake
命令时,我正在重建图像而没有MyApp
文件夹中的bin
文件夹。 When I leave the rake
command off I'm rebuilding the image with the bin
folder. 当我离开rake
命令时,我正在使用bin
文件夹重建图像。 And I know I'm truly rebuilding the images because I delete the cached versions before I rebuild them. 而且我知道我正在重建图像,因为我在重建之前删除了缓存的版本。
I finally figured out a resolution here. 我终于在这里找到了一个决议。 I added the rake rails:update:bin
call to the command just before the server starts. 我在服务器启动之前添加了rake rails:update:bin
调用命令。
I created the following shell script to set as the docker-compose.yml command 我创建了以下shell脚本来设置为docker-compose.yml命令
#!/bin/bash
rake rails:update:bin
# start the SSH server for connecting the debugger in development
/usr/sbin/sshd -D &
bundle exec rails s -p 3000 -b '0.0.0.0'
My docker-compose.yml looks like this 我的docker-compose.yml看起来像这样
version: '2'
services:
web:
build: .
command: /MyApp/docker-dev-start.sh
volumes:
- .:/MyApp
ports:
- "3000:3000"
- "3022:22"
and my dockerfile ended up looking like this 我的dockerfile最终看起来像这样
FROM ruby:2.2
RUN apt-get update && apt-get install -y \
build-essential \
libpq-dev \
nodejs \
openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:screencast' | chpasswd
RUN sed -i 's/PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
RUN mkdir /MyApp
WORKDIR /MyApp
ADD Gemfile /MyApp/Gemfile
ADD Gemfile.lock /MyApp/Gemfile.lock
RUN bundle install
ADD . /MyApp
The SSH server is included to be able to connect an external IDE for debugging. 包含SSH服务器以便能够连接外部IDE进行调试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.