Docker编写错误:服务';网络';未能生成:复制失败:禁止路径

Docker编写错误:服务';网络';未能生成:复制失败:禁止路径,docker,docker-compose,Docker,Docker Compose,我遵循docker官方教程在docker中设置rails,下面给出了相同的链接 我的Dockerfile # syntax=docker/dockerfile:1 FROM ruby:2.5 RUN apt-get update -qq && apt-get install -y nodejs postgresql-client WORKDIR /myapp COPY Gemfile /myapp/Gemfile COPY Gemfile.lock /myapp/Gemfile

我遵循docker官方教程在docker中设置rails,下面给出了相同的链接

我的Dockerfile

# syntax=docker/dockerfile:1
FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY ../compose /myapp

# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

# Configure the main process to run when running the image
CMD ["rails", "server", "-b", "0.0.0.0"]
docker-compose.yml

version: "3.9"
services:
  db:
    image: postgres
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: password
  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
运行此命令时出现的错误

docker-compose run --no-deps web rails new . --force --database=postgresql
错误:

Step 7/12 : COPY ../compose /myapp
ERROR: Service 'web' failed to build : COPY failed: forbidden path outside the build context: ../compose ()
我的目录结构是

docker-rails tree.
├── Dockerfile
├── Gemfile
├── Gemfile.lock
├── docker-compose.yml
└── entrypoint.sh

0 directories, 5 files

我对docker的设置比较陌生。我在SO中看到了类似的错误,但它们的设置文件不同,因此无法理解如何修复它。

您遇到了错误,因为您试图复制的文件不在生成上下文中。根据docker compose文档的构建上下文:

指向包含Dockerfile的目录的路径,或指向Dockerfile的url git存储库

当提供的值是相对路径时,它被解释为 相对于撰写文件的位置。此目录也是 发送到Docker守护程序的生成上下文

尝试将
COPY../compose/myapp
更改为
COPY

并在目录

…构建上下文之外的禁止路径…
”中的终端中运行构建命令-构建上下文是调用
dockerfile
的pwd表单。我们无法将此目录之外的数据复制到容器中。简而言之:我们不能在
dockerfile
中使用
。/
。我放弃了这一点,并用Golang创建了我的后端。现在一切都很顺利。