为 docker 容器更新 Ruby bin 文件夹的正确方法是什么?
What is the proper way to update the Ruby bin folder for a docker container?
我一直在尝试将 Rails 上现有的 Ruby 应用程序转换为在 docker 容器中开发。我不明白在哪里最好合并 rake rails:update:bin
命令。我试图将其作为 docker 文件的最后一行,但容器无法正常启动。让容器启动的唯一方法是在图像构建之外构建 bin,以便使用 ADD 命令拉入 bin 文件夹。
是否可以创建一个 docker文件来执行所有操作?
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
命令时,我正在重建 MyApp
文件夹中没有 bin
文件夹的图像。当我关闭 rake
命令时,我正在使用 bin
文件夹重建图像。而且我知道我真的在重建图像,因为我在重建它们之前删除了缓存的版本。
我终于想出了解决办法。我在服务器启动之前添加了对命令的 rake rails:update:bin
调用。
我创建了以下 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"
我的docker文件最终看起来像这样
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 进行调试。
我一直在尝试将 Rails 上现有的 Ruby 应用程序转换为在 docker 容器中开发。我不明白在哪里最好合并 rake rails:update:bin
命令。我试图将其作为 docker 文件的最后一行,但容器无法正常启动。让容器启动的唯一方法是在图像构建之外构建 bin,以便使用 ADD 命令拉入 bin 文件夹。
是否可以创建一个 docker文件来执行所有操作?
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
命令时,我正在重建 MyApp
文件夹中没有 bin
文件夹的图像。当我关闭 rake
命令时,我正在使用 bin
文件夹重建图像。而且我知道我真的在重建图像,因为我在重建它们之前删除了缓存的版本。
我终于想出了解决办法。我在服务器启动之前添加了对命令的 rake rails:update:bin
调用。
我创建了以下 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"
我的docker文件最终看起来像这样
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 进行调试。