更新Docker容器的Ruby bin文件夹的正确方法是什么?

我一直在转换一个现有的Ruby on Rails应用程序在docker容器中开发。 我不明白在哪里最好把rake rails:update:bin命令。 我试图把它作为docker文件的最后一行,但容器将无法正常启动。 我可以让容器启动的唯一方法是在图像构build之外构buildbin,以便使用ADD命令来拉取bin文件夹。

是否有可能创build一个dockerfile来完成所有的事情?


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 

我想添加下面一行到最后。

 RUN rake rails:update:bin 

当我尝试包括rake命令时,我正在重buildMyApp文件夹中没有bin文件夹的图像。 当我离开rake命令时,我正在用bin文件夹重build图像。 而且我知道我真的重build图像,因为我重build它们之前删除caching的版本。

我终于想出了一个决议。 我在服务器启动前添加了rake rails:update:bin调用。

我创build了下面的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' 

我的docker-compose.yml看起来像这样

 version: '2' services: web: build: . command: /MyApp/docker-dev-start.sh volumes: - .:/MyApp ports: - "3000:3000" - "3022:22" 

和我的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 

包括SSH服务器能够连接外部IDE进行debugging。