【问题标题】:Docker-compose build issueDocker-compose 构建问题
【发布时间】:2020-06-10 08:05:26
【问题描述】:

我正在尝试执行 docker-compose build 但 nginx 返回此错误:

rm: cannot remove '/etc/nginx/conf.d/default.conf': No such file or directory
ERROR: Service 'nginx' failed to build: The command '/bin/sh -c rm /etc/nginx/conf.d/default.conf' returned a non-zero code: 1

这里是 docker-compose.yml 和 Dockerfile:

version: '3'
volumes:
  pgdata:
services:
  python:
    build:
      context: .
      dockerfile: docker/python/Dockerfile
    environment:
      - DJANGO_SETTINGS_MODULE=sphinx_django.settings.prod
    ports:
    - 8000:8000
    depends_on:
      - db
    command: gunicorn -w 4 sphinx_django.wsgi:application -b 0.0.0.0:8000
  db:
    image: postgres:10.3
    restart: always
    environment:
      POSTGRES_USER: '121211'
      POSTGRES_HOST: db
      POSTGRES_PASS: '55555'
    volumes:
    - pgdata:/var/lib/postgresql/data
    ports:
    - "5432:5432"
  nginx:
     build:
       context: .
       dockerfile: docker/nginx/Dockerfile
     restart: always
     ports:
       - 8080:80
     depends_on:
        - python

还有 Dockerfile:

FROM nginx:latest
​
RUN rm /etc/nginx/conf.d/default.conf
​
COPY ./docker/nginx/nginx.conf /etc/nginx/conf.d/

【问题讨论】:

  • 你拉最新的图像了吗?无法重现错误,与您在上面发布的docker/nginx/Dockerfile 相同

标签: docker nginx docker-compose dockerfile devops


【解决方案1】:

复制您的Dockerfile 时,我得到:

Error response from daemon: Dockerfile parse error line 2: unknown instruction:

我认为这是编码的问题。尝试将您的 Dockerfile 转换为 UTF-8。

【讨论】:

    【解决方案2】:

    Context用于指定构建位置Dockerfile

    上下文

    包含 Dockerfile 的目录的路径或 url 到一个 git 存储库。

    从您的项目结构来看,default.conf 位于与您的Dockerfile 相同的目录中。

    你的 Dockerfile 应该是这样的:

    FROM nginx:latest
    ​
    RUN rm /etc/nginx/conf.d/default.conf
    ​
    COPY ./nginx.conf /etc/nginx/conf.d/
    

    【讨论】:

      猜你喜欢
      • 2017-11-08
      • 1970-01-01
      • 2020-07-11
      • 1970-01-01
      • 1970-01-01
      • 2022-12-04
      • 1970-01-01
      • 2020-01-22
      • 2017-03-24
      相关资源
      最近更新 更多