docker / getting-started

Getting started with Docker
Apache License 2.0
2.89k stars 6.4k forks source link

Problem with running the "Using Bind Mount" section command #116

Open UsamiChou opened 3 years ago

UsamiChou commented 3 years ago

I'm running this tutorial on Windows10 with docker desktop and entering command by Powershell. I followed the instruction to install WSL2 when I open docker desktop first time. After entering

docker run -dp 3000:3000 `
    -w /app -v "$(pwd):/app" `
    node:12-alpine `
    sh -c "yarn install && yarn run dev"

I can see a container running. And by using docker logs -f I can only see a error seems to be a yarn error. And the yarn-error.log:

Node version: 
  12.20.1

Platform: 
  linux x64

Trace: 
  Error: EPERM: operation not permitted, symlink '../../../parser/bin/babel-parser.js' -> '/app/node_modules/@babel/core/node_modules/.bin/parser'

npm manifest: 
  {
    "name": "101-app",
    "version": "1.0.0",
    "main": "index.js",
    "license": "MIT",
    "scripts": {
      "prettify": "prettier -l --write \"**/*.js\"",
      "test": "jest",
      "dev": "nodemon src/index.js"
    },
    "dependencies": {
      "body-parser": "^1.19.0",
      "express": "^4.17.1",
      "mysql": "^2.17.1",
      "sqlite3": "^4.1.0",
      "uuid": "^3.3.3",
      "wait-port": "^0.2.2"
    },
    "prettier": {
      "trailingComma": "all",
      "tabWidth": 4,
      "useTabs": false,
      "semi": true,
      "singleQuote": true
    },
    "devDependencies": {
      "jest": "^24.9.0",
      "nodemon": "^1.19.2",
      "prettier": "^1.18.2"
    }
  }

yarn manifest: 
  No manifest

Since I know little about Linux so after searching the error I still have no idea how this problem occured and how to solve it.

Hoping there could be someone explain this issue for me and provide me with some tips to solve it

Franz333 commented 3 years ago

Hi, I had a problem with that command too. Does the container keeps running or does it exit straightaway?

UsamiChou commented 3 years ago

Hi, I had a problem with that command too. Does the container keeps running or does it exit straightaway?

It exited right away and with the exit code 1

Franz333 commented 3 years ago

Hello, Try adding the path like this instead of using the $(pwd) variable: -w //app -v "//c/Users/UserName/getting-started":/app making sure you replace the values to point to the correct directory in your local hard disk

krlenell commented 3 years ago

Hello, Try adding the path like this instead of using the $(pwd) variable: -w //app -v "//c/Users/UserName/getting-started":/app making sure you replace the values to point to the correct directory in your local hard disk

Hey, this doesn't work for me. And I'd prefer not to be mounting things in my Windows directory, I keep everything in WSL 2 and Ubuntu directories.

krlenell commented 3 years ago

I figured out my issue, I wasn't in the app directory. This issue gives more information. https://github.com/docker/getting-started/issues/76#issue-674527916

teroxrr commented 2 years ago

I also struggled a lot with this section and none of the answers in this thread or the other threads related to the same issue seem to work for me.

I was getting a long error message apparently related to a Core.DockerException. Error status was 500.

I managed to fix this after finding this post: https://www.reddit.com/r/docker/comments/grjwl9/docker_run_rm_v_getting_error_response_from/

Here is the important part:

The -v mounts a location from the local directory to your running container. the left side of the colon in the location on the host computer and the right side is the location in the container that will now be linked together.

The problem was is that when you run Docker in windows you need to specifically give Docker access to this location. To give Docker access to your computer’s drives, right click on the Docker icon in your taskbar, then click “Settings…” and look for the "File Sharing" section. Add the location you want to share and you are good to go!!!

So, apparently it's a common configuration that must be set when using Docker on Windows in Hyper-V mode, as stated in the Official Documentation: https://docs.docker.com/desktop/windows/#file-sharing

I hope it's useful to somebody, it was a big headache for me.