无法使用docker-compose运行容器

时间:2019-08-29 16:06:50

标签: docker docker-compose dockerfile

在ubuntu vbox上执行以下shell时出现错误。

docker-compose up -d
Step 1/4 : FROM postgres:9.4
 ---> d1b08fdd94ed
Step 2/4 : RUN mkdir /docker-entrypoint-initdb.d/census/
 ---> Using cache
 ---> 35c38c9966fb
Step 3/4 : COPY ./sql/census/ /docker-entrypoint-initdb.d/census
ERROR: Service 'db' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder974990962/sql/census: no such file or directory

我在Google上进行了搜索,但没有获得解决此问题的提示。

您能帮我吗?

感谢您的关注。 最好的祝福, 丽基

文件夹结构

docker-compose.yml
db/Dockerfile
web/Dockerfile

docker-compose.yml

version: "3"

services:
  web:
    build:
      context: .
      dockerfile: docker/web/Dockerfile
    container_name: wazimap-vpuu
    environment:
      - DATABASE_URL=postgresql://postgres:postgres@db/postgres
    expose:
      - "8000"
    command: bash -c "python manage.py migrate --noinput && python manage.py runserver 0.0.0.0:8000"
    volumes:
      - .:/vpuu
    ports:
      - "8000:8000"
    depends_on:
      - db
  db:
    build:
      context: .
      dockerfile: docker/db/Dockerfile
    container_name: wazimap-postgres
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5
    volumes:
      - postgres-data:/var/lib/postgresql/data

volumes:
  postgres-data:

db / Dockerfile

FROM postgres:9.4

RUN mkdir /docker-entrypoint-initdb.d/census/
COPY sql/census/ /docker-entrypoint-initdb.d/census
COPY sql/extensions/ /docker-entrypoint-initdb.d/

web / Dockerfile

FROM ubuntu:18.04

ENV PYTHONUNBUFFERED 1

RUN apt-get update && apt install -y gdal-bin libgdal-dev
RUN apt install -y python-pip git

ENV CPLUS_INCLUDE_PATH /usr/include/gdal
ENV C_INCLUDE_PATH /usr/include/gdal

RUN mkdir /vpuu
WORKDIR /vpuu

COPY . /vpuu

RUN pip install -r requirements.txt

1 个答案:

答案 0 :(得分:1)

根据Dockerfile documentation

  

COPY指令从<src>复制新文件或目录,并将它们添加到容器的文件系统中,路径为<dest>

<src>是在docker-compose dockerfile指令的上下文中指定的

错误COPY failed: stat /var/lib/docker/tmp/docker-builder974990962/sql/census: no such file or directory表示在建筑物上下文中找不到文件sql/census

COPY,应在此之前将其放在构建上下文中。

相关问题