简体   繁体   English

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

[英]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.

相关问题 在Ruby数组中使用返回枚举器的方法的正确方法是什么? - What is the proper way to use methods that return an enumerator in Ruby array? 在Ruby 1.9中访问类变量的正确方法是什么? - What is the proper way to access class variables in Ruby 1.9? 将ruby对象映射到json的正确(版本安全)方法是什么? - What is the proper (version-safe) way to map ruby objects to json? 安装Ruby gem的正确方法是什么? 使用RVM还是Bundler? - What is the proper way to install a Ruby gem; Using RVM or Bundler? 使用React设计Ruby on Rails应用程序的正确方法是什么 - What's a proper way to design Ruby on Rails application with React 在Rails / Ruby中检查对象是否存在的正确方法是什么? - What is the proper way to check for existence of objects in Rails / Ruby? 在Ruby on Rails中访问虚拟属性的正确方法是什么? - What is the proper way to access virtual atributes in Ruby on Rails? 在 Ruby on Rails 中处理数据迁移的正确方法是什么? - What is the proper way of handling data migrations in Ruby on Rails? 并行运行Ruby脚本的正确方法是什么? - What's the proper way to run Ruby scripts in parallel? 在Ruby on Rails中处理地理区域设置的正确方法是什么? - What's the proper way to handle geographic locales in Ruby on Rails?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM