首页 > 解决方案 > CommandError: /code/manage.py 已经存在,将项目或应用程序覆盖到现有目录中不会替换冲突文件

问题描述

我正在尝试在 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
'''

我的 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/
'''

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

services:
  web:
    build: .
    command: python manage.py runserver case.xxxxxx.com:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"

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

标签: docker-compose

解决方案


您可能正在使用 Ubuntu Windows 子系统的 docker 客户端。这会导致 docker 的 Volume 功能出现问题。在windows powershell上运行docker run命令就不会出现这个问题了。


推荐阅读