在 Windows 中使用 docker-compose 创建挂载源路径时出错

Daw*_*n17 5 docker docker-compose

我正在尝试通过对每个应用程序进行 dockerizingdocker-compose并将它们放在一起来对我的 React-Flask 应用程序进行 dockerize 。

Dockerfile每个应用程序的s 如下所示:

反应 - 前端

FROM node:latest

WORKDIR /frontend/

ENV PATH /frontend/node_modules/.bin:$PATH

COPY package.json /frontend/package.json
COPY . /frontend/
RUN npm install --silent
RUN npm install react-scripts@3.0.1 -g --silent

CMD ["npm", "run", "start"]
Run Code Online (Sandbox Code Playgroud)

Flask - 后端

#Using ubuntu as our base
FROM ubuntu:latest

#Install commands in ubuntu, including pymongo for DB handling
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential
RUN python -m pip install pymongo[srv]

#Unsure of COPY command's purpose, but WORKDIR points to /backend
COPY . /backend
WORKDIR /backend/

RUN pip install -r requirements.txt

#Run order for starting up the backend
ENTRYPOINT ["python"]
CMD ["app.py"]
Run Code Online (Sandbox Code Playgroud)

当我只使用docker buildand时,它们中的每一个都可以正常工作docker up。我已经检查过它们在构建和独立运行时工作正常。然而,当我docker-compose updocker-compose.yml它看起来像

# Docker Compose
version: '3.7'

services:
  frontend:
    container_name: frontend
    build:
      context: frontend
      dockerfile: Dockerfile
    ports:
      - "3000:3000"
    volumes:
      - '.:/frontend'
      - '/frontend/node_modules'
  backend:
    build: ./backend
    ports:
      - "5000:5000"
    volumes:
       - .:/code
Run Code Online (Sandbox Code Playgroud)

给我下面的错误

Starting frontend                ... error
Starting dashboard_backend_1 ...

ERROR: for frontend  Cannot start service sit-frontend: error while creating mount source path '/host_mnt/c/Users/myid/DeskStarting dashboard_backend_1 ... error

ERROR: for dashboard_backend_1  Cannot start service backend: error while creating mount source path '/host_mnt/c/Users/myid/Desktop/dashboard': mkdir /host_mnt/c: file exists

ERROR: for frontend  Cannot start service frontend: error while creating mount source path '/host_mnt/c/Users/myid/Desktop/dashboard': mkdir /host_mnt/c: file exists

ERROR: for backend  Cannot start service backend: error while creating mount source path '/host_mnt/c/Users/myid/Desktop/dashboard': mkdir /host_mnt/c: file exists
ERROR: Encountered errors while bringing up the project.
Run Code Online (Sandbox Code Playgroud)

这是因为我使用的是 Windows 吗?可能是什么问题?提前致谢。

Joa*_*les 12

对我来说,唯一有效的方法是重新启动 Docker 守护进程


Von*_*onC 6

检查这是否与docker/for-win 问题 1560有关

我遇到过同样的问题。我能够通过运行来解决它:

docker volume rm -f [name of docker volume with error]
Run Code Online (Sandbox Code Playgroud)

然后重新启动docker,并运行:

docker-compose up -d --build
Run Code Online (Sandbox Code Playgroud)

我尝试了相同的步骤,但没有重新启动 Docker,但重新启动计算机并没有解决问题。
对我来说解决这个问题的方法是删除有错误的卷,重新启动我的泊坞窗,然后再次进行构建。

其他原因:

在 Windows 上,这可能是由于用户密码更改所致。取消选中该框以停止共享驱动器,然后允许 Docker 检测到您正在尝试安装驱动器并共享它。

https://user-images.githubusercontent.com/470472/36745728-49101172-1ba5-11e8-94da-1386cfba9702.png

还提到:

  • 我只是跑docker-compose down了然后docker-compose up。为我工作。

  • 我尝试过docker container prune然后按y删除所有停止的容器。这个问题已经消失了。