首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >命令'/bin/sh -c bundle‘返回一个非零代码: 10

命令'/bin/sh -c bundle‘返回一个非零代码: 10
EN

Stack Overflow用户
提问于 2018-03-26 18:13:51
回答 1查看 6.4K关注 0票数 5

我的当前文件夹是:/home/user/Desktop/me/docker-kubernets

1.运行命令:

代码语言:javascript
复制
docker run -it --rm --user "$(id -u):$(id -g)" \
   -v "$PWD":/usr/src/app -w /usr/src/app rails rails new --skip-bundle --api --database postgresql webapp

cd webapp

2 webapp.conf

代码语言:javascript
复制
server {
  listen 80;
  server_name _;
  root /home/user/Desktop/me/docker-kubernets;

  passenger_enabled on;
  passenger_user app;

  passenger_ruby /usr/bin/ruby2.4;
}

3 rails-env.conf

代码语言:javascript
复制
env SECRET_KEY_BASE;
env DATABASE_URL;
env DATABASE_PASSWORD;

4.文档

代码语言:javascript
复制
FROM phusion/passenger-ruby24
# Set correct environment variables.
ENV HOME /root
# Use baseimage-docker's init process.
CMD ["/sbin/my_init"]
# Additional packages: we are adding the netcat package so we can
# make pings to the database service
RUN apt-get update && apt-get install -y -o Dpkg::Options::="--force-confold" netcat
# Enable Nginx and Passenger
RUN rm -f /etc/service/nginx/down
# Add virtual host entry for the application. Make sure
# the file is in the correct path
RUN rm /etc/nginx/sites-enabled/default
ADD webapp.conf /etc/nginx/sites-enabled/webapp.conf
# In case we need some environmental variables in Nginx. Make sure
# the file is in the correct path
ADD rails-env.conf /etc/nginx/main.d/rails-env.conf
# Install gems: it's better to build an independent layer for the gems
# so they are cached during builds unless Gemfile changes WORKDIR /tmp
ADD Gemfile /tmp/
ADD Gemfile.lock /tmp/
RUN bundle install
# Copy application into the container and use right permissions: passenger
# uses the app user for running the application RUN mkdir /home/app/webapp
COPY . /home/user/Desktop/me/docker-kubernets
RUN usermod -u 1000 app
RUN chown -R app:app /home/user/Desktop/me/docker-kubernets
WORKDIR /home/user/Desktop/me/docker-kubernets
# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
EXPOSE 80

5 setup.sh

代码语言:javascript
复制
#!/bin/sh

echo "Waiting PostgreSQL to start on 5432..."

while ! nc -z postgres 5432; do
  sleep 0.1
done

echo "PostgreSQL started"

bin/rails db:migrate

为该文件添加正确的执行权限

代码语言:javascript
复制
chmod +x setup.sh

6 docker-compose.yml

代码语言:javascript
复制
version: '2'
services:
  webapp_setup:
    build: .
    depends_on:
      - postgres
    environment:
      - PASSENGER_APP_ENV=development
    entrypoint: ./setup.sh
  webapp:
    container_name: webapp
    build: .
    depends_on:
      - postgres
      - webapp_setup
    environment:
      - PASSENGER_APP_ENV=development
    ports:
      - "80:80"
    volumes:
      - .:/home/user/Desktop/me/docker-kubernets

  postgres:
    image: postgres:10.2
    environment:
      - POSTGRES_PASSWORD=mysecretpassword
      - POSTGRES_USER=webapp
      - POSTGRES_DB=webapp_development
    volumes_from:
      - postgres_data
  postgres_data:
      image: postgres:10.2
      volumes:
        - /var/lib/postgresql/data
      command: /bin/true

7.生成Gemfile.lock

代码语言:javascript
复制
docker run --rm -v $(pwd):/usr/src/app -w /usr/src/app ruby:2.4.2 bundle lock

8 docker-compose build

我得到了错误:

代码语言:javascript
复制
Could not locate Gemfile
    ERROR: Service 'webapp_setup' failed to build: The command '/bin/sh -c bundle install' returned a non-zero code: 10

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-26 19:30:35

我在Dockerfile中做了这些修改,它的工作原理就像一种魅力:

代码语言:javascript
复制
FROM phusion/passenger-ruby24
# Set correct environment variables.
ENV HOME /root
# Use baseimage-docker's init process.
CMD ["/sbin/my_init"]
# Additional packages: we are adding the netcat package so we can
# make pings to the database service
RUN apt-get update && apt-get install -y -o Dpkg::Options::="--force-confold" netcat
# Enable Nginx and Passenger
RUN rm -f /etc/service/nginx/down
# Add virtual host entry for the application. Make sure
# the file is in the correct path
RUN rm /etc/nginx/sites-enabled/default
ADD webapp.conf /etc/nginx/sites-enabled/webapp.conf
# In case we need some environmental variables in Nginx. Make sure
# the file is in the correct path
ADD rails-env.conf /etc/nginx/main.d/rails-env.conf
# Install gems: it's better to build an independent layer for the gems
# so they are cached during builds unless Gemfile changes WORKDIR /tmp

COPY Gemfile* /tmp/
WORKDIR /tmp
RUN bundle install

# Copy application into the container and use right permissions: passenger
# uses the app user for running the application 
# RUN mkdir /home/me/Desktop/sg/docker-kubernets
COPY . /home/me/Desktop/sg/docker-kubernets
RUN usermod -u 1000 app
RUN chown -R app:app /home/me/Desktop/sg/docker-kubernets
WORKDIR /home/me/Desktop/sg/docker-kubernets

# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
EXPOSE 80

revision 2.4.2p198 (2017-09-14修订版59899) x86_64-linux

我希望能帮上忙!

致以问候!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49498020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档