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

lee*_*jun 5 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
 ---> 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
'''
Run Code Online (Sandbox Code Playgroud)

但是当我运行 compose up 时..我看到以下错误。

'''
$ 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
'''
Run Code Online (Sandbox Code Playgroud)

如果我尝试这个

'''
docker-compose run web django-admin startproject composeexample .
'''
Run Code Online (Sandbox Code Playgroud)

它说

'''
CommandError: /code/manage.py already exists, overlaying a project or app into an existing directory won't replace conflicting files
'''
Run Code Online (Sandbox Code Playgroud)

我的 Dockerfile 是

'''
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/
'''
Run Code Online (Sandbox Code Playgroud)

我的 docker-compose.yml 是 ''' 版本:'3'

services:
  web:
    build: .
    command: python manage.py runserver case.xxxxxx.com:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
Run Code Online (Sandbox Code Playgroud)

''' 我如何解决 composeexample 的问题?它甚至没有创建(因为我在文件夹中看不到它)..请您的建议。

Mih*_*hai -1

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

在你的 Dockerfile 中:

COPY . /code/
Run Code Online (Sandbox Code Playgroud)

在你的 docker-compose.yml 中:

    volumes:
      - .:/code
Run Code Online (Sandbox Code Playgroud)

我建议您从 Dockerfile 中删除 COPY 语句并使用 docker-compose 重新运行容器。

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

RUN mkdir /code
WORKDIR /code
Run Code Online (Sandbox Code Playgroud)

这不是错误,但 WORKDIR 已经创建了该文件夹(如果该文件夹不存在)。