这个问题以前有人问过。但是我似乎无法解决这个问题。我正在尝试将文件复制到我的 docker 容器,但它一直告诉我该目录不存在,即使它存在。我可以复制其他文件夹,但不能复制这个特定文件夹。
我的目录结构简化了:
- app
--.envs
-- .local
-- .django
--requirements
-- production
-- local
--compose
-- morefiles
当我运行时COPY ./requirements /requirements
,这可以正常工作。但当我运行时COPY ./.envs/.local/.django /
它告诉我:
服务“django”构建失败:复制失败:stat /var/lib/docker/tmp/docker-builder264874195/.envs/.local/.django:没有这样的文件或目录
我认为这.envs
是被排除在外的地方,但我不知道在哪里。我像推荐的那样检查了 docker-ignore 文件
复制失败:stat /var/lib/docker/tmp/docker-builder918577595/...,但如果我删除 中的所有内容,dockerignore
也会收到相同的错误。
我尝试重命名该文件夹,.
但结果仍然相同。不太确定我还能尝试什么。我尝试更改在其中移动命令的路径,Dockerfile
但什么也没有。我对 ADD 也有同样的行为。
我的docker-compose
文件:
version: '3'
volumes:
local_postgres_data: {}
local_postgres_data_backups: {}
services:
django:
build:
context: .
dockerfile: ./compose/local/django/Dockerfile
image: mywebsite_local_django
depends_on:
- postgres
volumes:
- .:/app
env_file:
- ./.envs/.local/.django
- ./.envs/.local/.postgres
ports:
- "8000:8000"
command: /start
postgres:
build:
context: .
dockerfile: ./compose/production/postgres/Dockerfile
image: mywebsite_production_postgres
volumes:
- local_postgres_data:/var/lib/postgresql/data
- local_postgres_data_backups:/backups
env_file:
- ./.envs/.local/.postgres
这是我的 dockerfile:
FROM python:3.8-alpine
COPY ./.envs/.production/.django /
COPY ./compose/local/django/pre_deploy_hook /
RUN chmod +x /pre_deploy_hook && /pre_deploy_hook
ENV PYTHONUNBUFFERED 1
ARG ADMIN_PORT=some_default_value
ENV ADMIN_PORT=${ADMIN_PORT}
ARG DJANGO_AWS_ACCESS_KEY_ID=defaultvalueoverwritteninnextline
ENV DJANGO_AWS_ACCESS_KEY_ID=${DJANGO_AWS_ACCESS_KEY_ID}
ARG DJANGO_AWS_SECRET_ACCESS_KEY=defaultvalueoverwritteninnextline
ENV DJANGO_AWS_SECRET_ACCESS_KEY=${DJANGO_AWS_SECRET_ACCESS_KEY}
ARG DJANGO_AWS_STORAGE_BUCKET_NAME=defaultvalueoverwritteninnextline
ENV DJANGO_AWS_STORAGE_BUCKET_NAME=${DJANGO_AWS_STORAGE_BUCKET_NAME}
ARG DJANGO_SECRET_KEY=defaultvalueoverwritteninnextline
ENV DJANGO_SECRET_KEY=${DJANGO_SECRET_KEY}
RUN apk update \
# psycopg2 dependencies
&& apk add --virtual build-deps gcc python3-dev musl-dev \
&& apk add postgresql-dev \
# Pillow dependencies
&& apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \
# CFFI dependencies
&& apk add libffi-dev py-cffi \
# Translations dependencies
&& apk add gettext \
# https://docs.djangoproject.com/en/dev/ref/django-admin/#dbshell
&& apk add postgresql-client \
## Needed for sphinx https://github.com/pydanny/cookiecutter-django/issues/1747
&& apk add make
##Needed when installing pandas as requirement
#RUN apk add --update curl gcc g++
#RUN ln -s /usr/include/locale.h /usr/include/xlocale.h
# Requirements are installed here to ensure they will be cached.
COPY ./requirements /requirements
RUN pip install -r /requirements/local.txt
COPY ./compose/production/django/entrypoint /entrypoint
RUN sed -i 's/\r//' /entrypoint
RUN chmod +x /entrypoint
COPY ./compose/local/django/start /start
RUN sed -i 's/\r//' /start
RUN chmod +x /start
WORKDIR /app
ENTRYPOINT ["/entrypoint"]
难道是我在compose文件中指定了.env文件?因为通过将文件放入另一个文件夹中它可以工作......但这不是我想要的......