使用docker-compose锁定Docker容器中的package.json文件 [英] Locked package.json files in Docker container using docker-compose

查看:354
本文介绍了使用docker-compose锁定Docker容器中的package.json文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Docker for Mac和Docker Compose用于Node.js应用程序的开发,并且 package.json 文件被锁定时遇到错误.在正在运行的容器中运行npm install --save <package>之后的具体错误是:

I'm using Docker for Mac and Docker Compose for development of a Node.js application and I'm experiencing an error with the package.json file being locked. The specific error after running npm install --save <package> within a running container is:

npm WARN saveError EBUSY: resource busy or locked, rename
'/Example/package.json.1647356251' -> '/Example/package.json'

简化的包装结构为:

▾ docker/
    Dockerfile
  docker-compose.yaml
  package.json

Dockerfile 包含:

FROM node:9.5
ENV SOURCE_CODE /Example
COPY package.json $SOURCE_CODE/package.json
RUN npm --prefix $SOURCE_CODE install $SOURCE_CODE
WORKDIR $SOURCE_CODE

docker-compose.yaml 文件包含:

version: "3"

services:
  node:
    build:
      context: ./
      dockerfile: ./docker/Dockerfile
    volumes:
      - ./node_modules/:/Example/node_modules/
      - ./package.json:/Example/package.json

package.json 文件包含:

{
  "name": "example",
  "version": "1.0.0",
  "description": "example",
  "license": "UNLICENSED"
}

运行docker-compose run --entrypoint bash node以启动bash,然后在容器内运行npm install --save redux会产生有关 package.json 文件被锁定的警告,但是可以将文件写入主机上的node_modules 目录.如何避免使用这种结构锁定 package.json 文件?

Running docker-compose run --entrypoint bash node to start bash, then running npm install --save redux inside the container yields the warning about the package.json file being locked, however files are able to be written in the node_modules directory on the host. How can I avoid locks on package.json file using this structure?

推荐答案

我遇到了相同的问题,我通过安装 package.json 所在的文件夹而不是 package来解决此问题. json 本身.

I encountered the same issue and I solved this by mounting the folder where package.json is located instead of package.json itself.

version: "3"

services:
  node:
    build:
      context: ./
      dockerfile: ./docker/Dockerfile
    volumes:
      - .:/Example

直接安装 package.json 是因为卷似乎锁定了文件.

Mounting package.json directly as a volume seems to lock the file.

这篇关于使用docker-compose锁定Docker容器中的package.json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆