一年中断后,我尝试使用docker / docker-compose运行默认的Rails 6项目。
起初,我遇到捆绑器问题。但这是通过[XmlInclude(typeof(Person))]
[Serializable]
public class Person ...
现在我遇到了纱线问题。您能否看一下以下配置并告诉我我做错了什么。谢谢!
Dockerfile
ENV BUNDLER_VERSION 2.0.1
docker-compose.yml
FROM ruby:2.6.3
RUN apt-get update -qq && apt-get install -y nodejs yarn postgresql-client
RUN mkdir -p /app
WORKDIR /app
COPY . /app
ENV BUNDLER_VERSION 2.0.1
RUN gem install bundler && bundle install --jobs 20 --retry 5
RUN yarn install
EXPOSE 3000
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]
这是FROM ruby:2.6.3
version: '3'
services:
db:
image: postgres
volumes:
- ./tmp/db:/var/lib/postgresql/data
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
的输出
在安装了gem之后,我可以看到以下输出:
docker-compose build
编辑
如果我使用以下Dockerfile,它将起作用。但是我认为这不是最好的解决方案。
Removing intermediate container b74374c81e66
---> bbb8e3ba24d1
Step 8/10 : RUN yarn install
---> Running in 3343917857c7
Parsing scenario file install
ERROR: [Errno 2] No such file or directory: 'install'
ERROR: Service 'web' failed to build: The command '/bin/sh -c yarn install' returned a non-zero code: 1
答案 0 :(得分:1)
有时在使用apt来安装yarn时在主机上安装了cmdtest
可能会导致问题尝试执行以下操作:
RUN apt-get remove -y cmdtest && apt-get update -qq && apt-get install -y nodejs postgresql-client
然后使用脚本安装yrn:
curl -o- -L https://yarnpkg.com/install.sh | bash
如果仍然无法正常工作,请参阅此commit
答案 1 :(得分:1)
我的Dockerfile的前几行如下:
FROM ruby:2.5.1
# Ensure we install an up-to-date version of Node
# See https://github.com/yarnpkg/yarn/issues/2888
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
# Ensure latest packages for Yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
# Allow apt to work with https-based sources
RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \
apt-transport-https \
nodejs \
postgresql-client \
yarn