Я пытаюсь установить rails 6 с webpacker на докере, и я получаю странную ошибку, когда docker up завершает работу:
Errno::ENOENT: No such file or directory - getcwd
Как только я ssh в контейнере, я получаю это:
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
Это мой DockerFile:
ARG RUBY_VERSION
# See explanation below
FROM ruby:$RUBY_VERSION
ARG PG_MAJOR
ARG NODE_MAJOR
ARG BUNDLER_VERSION
ARG YARN_VERSION
# Add PostgreSQL to sources list
RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
# Add NodeJS to sources list
RUN curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR.x | bash -
# Add Yarn to the sources list
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo 'deb http://dl.yarnpkg.com/debian/ stable main' > /etc/apt/sources.list.d/yarn.list
# Install dependencies
# We use an external Aptfile for that, stay tuned
COPY ./dockerDev/Aptfile /tmp/Aptfile
RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
build-essential \
postgresql-client-$PG_MAJOR \
nodejs \
yarn=$YARN_VERSION-1 \
$(cat /tmp/Aptfile | xargs) && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
truncate -s 0 /var/log/*log
# Configure bundler and PATH
ENV LANG=C.UTF-8 \
GEM_HOME=/bundle \
BUNDLE_JOBS=4 \
BUNDLE_RETRY=3
ENV BUNDLE_PATH $GEM_HOME
ENV BUNDLE_APP_CONFIG=$BUNDLE_PATH \
BUNDLE_BIN=$BUNDLE_PATH/bin
ENV PATH /app/bin:$BUNDLE_BIN:$PATH
# Upgrade RubyGems and install required Bundler version
RUN gem update --system && \
gem install bundler:$BUNDLER_VERSION
# Create a directory for the app code
RUN mkdir -p /app
WORKDIR /app
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
COPY package.json /app/package.json
COPY yarn.lock /app/yarn.lock
COPY . /app
# Add a script to be executed every time the container starts. Fixes a Rails-specific issue that prevents the server from restarting when a certain server.pid file pre-exists
# COPY entrypoint.sh /usr/bin/
# RUN chmod +x /usr/bin/entrypoint.sh
# ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
Это мой docker-compose:
version: '3.5'
services:
app: &app
build:
context: .
dockerfile: ./Dockerfile
args:
RUBY_VERSION: '2.6.3'
PG_MAJOR: '10'
NODE_MAJOR: '11'
YARN_VERSION: '1.13.0'
BUNDLER_VERSION: '2.0.2'
image: treasure-dev:1.0.0
tmpfs:
- /tmp
backend: &backend
<<: *app
stdin_open: true
tty: true
volumes:
- .:/app
# !!!! WARNING !!! For MacOs add this line. It does have a cost though
# https://docs.docker.com/docker-for-mac/osxfs-caching/#cached
# - .:/app:cached
- rails_cache:/app/tmp/cache
- bundle:/bundle
- node_modules:/app/node_modules
- packs:/app/public/packs
- ./dockerDev/.psqlrc:/root/.psqlrc:ro
environment:
- NODE_ENV=development
- RAILS_ENV=${RAILS_ENV:-development}
# - REDIS_URL=redis://redis:6379/
- DATABASE_URL=postgres://postgres@postgres
- BOOTSNAP_CACHE_DIR=/bundle/bootsnap
- WEBPACKER_DEV_SERVER_HOST=webpacker
- WEB_CONCURRENCY=1
- HISTFILE=/app/log/.bash_history
- PSQL_HISTFILE=/app/log/.psql_history
- EDITOR=vi
depends_on:
- postgres
# - redis
# runner:
# <<: *backend
# command: /bin/bash
# ports:
# - '3000:3000'
# - '3002:3002'
rails:
<<: *backend
command: ["/bin/bash","-c", "script/start-rails"]
ports:
- '3054:3054'
# sidekiq:
# <<: *backend
# command: bundle exec sidekiq -C config/sidekiq.yml
postgres:
image: postgres:10.10
volumes:
- .psqlrc:/root/.psqlrc:ro
- postgres-data:/var/lib/postgresql/data
- ./log:/root/log:cached
environment:
- PSQL_HISTFILE=/root/log/.psql_history
ports:
- "5432:5432"
# redis:
# image: redis:3.2-alpine
# volumes:
# - redis:/data
# ports:
# - 6379
webpacker:
<<: *backend
command: ["script/start-webpack-dev-server"]
ports:
- '3035:3035'
volumes:
- .:/app:cached
- bundle:/bundle
- node_modules:/app/node_modules
- packs:/app/public/packs
environment:
- NODE_ENV=${NODE_ENV:-development}
- RAILS_ENV=${RAILS_ENV:-development}
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0
volumes:
postgres-data:
# redis:
bundle:
node_modules:
rails_cache:
packs:
Это мой скрипт стартовых рельсов
#!/bin/bash
echo "Preparing container. This may take a while..."
wait_service ${DATABASE_URL:-db} 5432
wait_service webpacker 3035
bundle check || bundle install
yarn install --frozen-lockfile
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake db:seed
echo "Done."
bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3054 -b '0.0.0.0'"
Это мои версии docker-compose и docker:
treasure rails-6-new-postgresql % docker -v
Docker version 19.03.4, build 9013bf5
treasure rails-6-new-postgresql % docker-compose -v
docker-compose version 1.24.1, build 4667896b
treasure rails-6-new-postgresql %
Я немного прочитал в Google, и это ошибка Docker, но я не нашел, как мне ее пропустить, мой сервер railsне начнется из-за этого. Есть идеи?
Обновление: Это будет актуальная проблема на github: https://github.com/docker/for-mac/issues/1509
Парень сказал, что они делают это:
@ryfow might be on to something. In my case there was no subdirectory mount, but two different containers based on the same image were mounting a volume from the same host directory at the same path inside the container. We have two different services in the same repository with virtually identical dependencies, so docker-compose.yml just launches the same image twice with different commands and configurations. We now have a workaround in place which just retries in a loop until it works, so we haven't noticed the problem in a while, but I suspect it's still happening.
Но мне нужен переводза то, что он делает, или фрагмент кода.
Обновление 2 для Дэвида:
Dockerfile остается без изменений
docker-compose можно уменьшить до:
version: '3.5'
services:
app: &app
build:
context: .
dockerfile: ./Dockerfile
args:
RUBY_VERSION: '2.6.3'
PG_MAJOR: '10'
NODE_MAJOR: '11'
YARN_VERSION: '1.13.0'
BUNDLER_VERSION: '2.0.2'
image: treasure-dev:1.0.0
tmpfs:
- /tmp
backend: &backend
<<: *app
stdin_open: true
tty: true
volumes:
- .:/app
# !!!! WARNING !!! For MacOs add this line. It does have a cost though
# https://docs.docker.com/docker-for-mac/osxfs-caching/#cached
# - .:/app:cached
- rails_cache:/app/tmp/cache
- bundle:/bundle
- node_modules:/app/node_modules
- packs:/app/public/packs
- ./dockerDev/.psqlrc:/root/.psqlrc:ro
environment:
- NODE_ENV=development
- RAILS_ENV=${RAILS_ENV:-development}
# - REDIS_URL=redis://redis:6379/
- DATABASE_URL=postgres://postgres@postgres
- BOOTSNAP_CACHE_DIR=/bundle/bootsnap
- WEBPACKER_DEV_SERVER_HOST=webpacker
- WEB_CONCURRENCY=1
- HISTFILE=/app/log/.bash_history
- PSQL_HISTFILE=/app/log/.psql_history
- EDITOR=vi
depends_on:
- postgres
# - redis
rails:
<<: *backend
command: ["/bin/bash","-c", "script/start-rails"]
ports:
- '3054:3054'
postgres:
image: postgres:10.10
volumes:
- .psqlrc:/root/.psqlrc:ro
- postgres-data:/var/lib/postgresql/data
- ./log:/root/log:cached
environment:
- PSQL_HISTFILE=/root/log/.psql_history
ports:
- "5432:5432"
volumes:
postgres-data:
bundle:
node_modules:
rails_cache:
packs: