Docker compose CommandError:/code/manage.py已存在,将项目或应用程序覆盖到现有目录中;不能替换冲突的文件

Docker compose CommandError:/code/manage.py已存在,将项目或应用程序覆盖到现有目录中;不能替换冲突的文件,docker-compose,Docker Compose,我正在尝试在windows上运行linux docker,并收到此错误 身材很好 ''' $ docker-compose build Building web Step 1/11 : FROM python:3 ---> 42d620af35be Step 2/11 : ENV PYTHONUNBUFFERED 1 ---> Using cache ---> b43065732d6e Step 3/11 : RUN apt-get update -y --->

我正在尝试在windows上运行linux docker,并收到此错误

身材很好

'''
$ docker-compose build
Building web
Step 1/11 : FROM python:3
 ---> 42d620af35be
Step 2/11 : ENV PYTHONUNBUFFERED 1
 ---> Using cache
 ---> b43065732d6e
Step 3/11 : RUN apt-get update -y
 ---> Using cache
 ---> 6f65e0da9e14
Step 4/11 : RUN apt-get install -y unixodbc unixodbc-dev
 ---> Using cache
 ---> 2a9d7445a991
Step 5/11 : RUN easy_install pip
 ---> Using cache
 ---> 5994e6452e09
Step 6/11 : RUN mkdir /code
 ---> Using cache
 ---> d0eaa870fb98
Step 7/11 : WORKDIR /code
 ---> Using cache
 ---> af78d4b35f26
Step 8/11 : RUN pip uninstall django
 ---> Using cache
 ---> 92f983bfef88
Step 9/11 : COPY requirements.txt /code/
 ---> Using cache
 ---> 3c0031987286
Step 10/11 : RUN pip install -r requirements.txt
 ---> Using cache
 ---> 3915127d3d58
Step 11/11 : COPY . /code/
 ---> Using cache
 ---> de872685c733
Successfully built de872685c733
Successfully tagged djangoproject_web:latest
'''
但是当我跑上去的时候。。我看到下面的错误

'''
$ docker-compose up
Creating djangoproject_web_1 ... done
Attaching to djangoproject_web_1
web_1  | Watching for file changes with StatReloader
web_1  | Performing system checks...
web_1  |
web_1  | System check identified no issues (0 silenced).
web_1  |
web_1  | You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
web_1  | Run 'python manage.py migrate' to apply them.
web_1  | July 23, 2019 - 03:21:21
web_1  | Django version 2.2.3, using settings 'composeexample.settings'
web_1  | Starting development server at http://case.xxxxxx.com:8000/
web_1  | Quit the server with CONTROL-C.
web_1  | Error: [Errno -2] Name or service not known
djangoproject_web_1 exited with code 1
'''
如果我试试这个

'''
docker-compose run web django-admin startproject composeexample .
'''
上面说

'''
CommandError: /code/manage.py already exists, overlaying a project or app into an existing directory won't replace conflicting files
'''
我的文件是

'''
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN apt-get update -y
RUN apt-get install -y unixodbc unixodbc-dev
RUN easy_install pip
RUN mkdir /code
WORKDIR /code
RUN pip uninstall django
COPY requirements.txt /code/
RUN pip install -r requirements.txt 
COPY . /code/
'''
我的docker-compose.yml是 ''' 版本:“3”

services:
  web:
    build: .
    command: python manage.py runserver case.xxxxxx.com:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
'''
如何使用composeexample解决此问题?它甚至没有被创建(因为我在文件夹中看不到它)。。请给我你的建议

您有两个冲突/覆盖语句:

在Dockerfile中:

COPY . /code/
在docker-compose.yml中:

    volumes:
      - .:/code
我建议您从docker文件中删除COPY语句,并使用docker compose重新运行容器

此外,您还可以在此处删除RUN命令:

RUN mkdir /code
WORKDIR /code

这不是一个错误,但是WORKDIR已经创建了文件夹,如果它不存在的话。

您可能正在使用UbuntuWindows子系统的docker客户端。这给docker的音量特性带来了问题。
在windows powershell上运行
docker Run
命令,此问题将不会出现。

问题是,您正在尝试创建一个已通过重新运行该命令创建的项目

docker-compose run web django-admin startproject composeexample .
快跑

docker-compose run web