Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while creating mount source path when using docker-compose in Windows

I am trying to dockerize my React-Flask app by dockerizing each one of them and using docker-compose to put them together.

Here the Dockerfiles for each app look like:

React - Frontend

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 [email protected] -g --silent

CMD ["npm", "run", "start"]

Flask - Backend

#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"]

Each of them works fine when I just use docker build and docker up. I've checked that they work fine when they are built and ran independently. However, when I docker-compose up the docker-compose.yml which looks like

# 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

Gives me the error below

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.

Did this happen because I am using Windows? What can be the issue? Thanks in advance.

like image 728
Dawn17 Avatar asked Oct 02 '19 03:10

Dawn17


People also ask

What is mount path in Docker?

Bind mounts have been around since the early days of Docker. Bind mounts have limited functionality compared to volumes. When you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced by its absolute path on the host machine.

How do I add a docker mount?

To mount a data volume to a container add the --mount flag to the docker run command. It adds the volume to the specified container, where it stores the data produced inside the virtual environment. Replace [path_in_container] with the path where you want to place the data volume in the container.

What are the two types of mounts in Docker?

Basically, there are 3 types of mounts which you can use in your Docker container viz. Volumes, Bind mount and tmpfs mounts.


3 Answers

For me the only thing that worked was restarting the Docker deamon

like image 156
Joaquín L. Robles Avatar answered Oct 19 '22 17:10

Joaquín L. Robles


Check if this is related to docker/for-win issue 1560

I had the same issue. I was able to resolve it by running:

docker volume rm -f [name of docker volume with error]

Then restarting docker, and running:

docker-compose up -d --build

I tried these same steps without restarting my docker, but restarting my computer and that didn't resolve the issue.
What resolved the issue for me was removing the volume with the error, restarting my docker, then doing a build again.

Other cause:

On Windows this may be due to a user password change. Uncheck the box to stop sharing the drive and then allow Docker to detect that you are trying to mount the drive and share it.

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

Also mentioned:

  • I just ran docker-compose down and then docker-compose up. Worked for me.

  • I have tried with docker container prune then press y to remove all stopped containers. This issue has gone.

like image 28
VonC Avatar answered Oct 19 '22 15:10

VonC


I saw this after I deleted a folder I'd shared with docker and recreated one with the same name. I think this deleted the permissions. To resolve it I:

  • Unshared the folder in docker settings
  • Restarted docker
  • Ran docker container prune
  • Ran docker-compose build
  • Ran docker-compose up.
like image 25
Alexander Townsend Avatar answered Oct 19 '22 17:10

Alexander Townsend