权限在Docker容器中被拒绝

时间:2020-11-12 14:02:11

标签: docker dockerfile

我是Docker的新手,我正在尝试按照this教程运行容器,并且在使用--volume-v时遇到了一些问题,如下所示:

docker run -v <absolute path to host directory>:<absolute path to container working directory> <image id>

我的看起来像这样:

docker run -p 3000:3000 -v /usr/app/node_modules -v "$(pwd)":/usr/app 900a3497fc39

抛出的错误是这样的:

npm ERR! code EACCES
npm ERR! syscall open
npm ERR! path /usr/app/package.json
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, open '/usr/app/package.json'
npm ERR!  [Error: EACCES: permission denied, open '/usr/app/package.json'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'open',
npm ERR!   path: '/usr/app/package.json'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-11-12T13_39_38_626Z-debug.log

我构建的图像没有任何问题:

docker build -f Dockerfile.dev .
Sending build context to Docker daemon  23.55kB
Step 1/6 : FROM node
 ---> f1974cfde44f
Step 2/6 : WORKDIR /usr/app
 ---> Using cache
 ---> 120da5dd5fa4
Step 3/6 : COPY ./package.json ./
 ---> Using cache
 ---> 040ba41014c8
Step 4/6 : RUN npm install
 ---> Using cache
 ---> 96315e12e5d0
Step 5/6 : COPY . .
 ---> db93b8725037
Step 6/6 : CMD [ "npm", "run", "dev" ]
 ---> Running in 9c9d58318420
Removing intermediate container 9c9d58318420
 ---> 900a3497fc39
Successfully built 900a3497fc39

我的Dockerfile.dev看起来像这样:

FROM node

WORKDIR /usr/app

COPY ./package.json ./
RUN npm install

COPY . .

CMD [ "npm", "run", "dev" ]

package.json看起来像这样:

{
  "name": "vite-counter",
  "scripts": {
    "dev": "vite",
    "build": "vite build"
  },
  "dependencies": {
    "vue": "^3.0.0-beta.15"
  },
  "devDependencies": {
    "vite": "^1.0.0-beta.3",
    "@vue/compiler-sfc": "^3.0.0-beta.15"
  }
}

据我了解,我在容器中没有足够的权限来运行它。这正是我在本教程中遵循的内容。我在做什么错,该如何解决?

0 个答案:

没有答案