【问题标题】:Why can't yarn.lock found in my Docker container?为什么在我的 Docker 容器中找不到 yarn.lock?
【发布时间】:2020-10-10 20:40:44
【问题描述】:

我正在运行一个 Node.js 脚本,如下所示:docker run -it --rm -u node --name build_container -v $(pwd):/home/node/app -w "/home/node/app" node:lts bash -c "yarn install --no-cache --frozen-lockfile"

但是,脚本日志显示 info No lockfile found,更奇怪的是,发现了一条消息,上面写着 package-lock.json。但是,工作目录没有package-lock

有什么想法可能是问题吗?

【问题讨论】:

  • 说它是自动添加的..但是项目的结构是什么?

标签: node.js docker yarnpkg


【解决方案1】:

我建议使用您自己的 Dockerfile 来构建您的图像 - 然后在构建中运行它 - 就像这样:

Dockerfile

FROM node:12-alpine

# Create work directory
RUN mkdir -p /express
WORKDIR /express

# Bundle app sources
COPY . .

# Build app
RUN yarn install --prod --frozen-lockfile && yarn run build

EXPOSE 3000

# Set default NODE_ENV to production
ENV NODE_ENV production
ENTRYPOINT [ "yarn", "start" ]

.dockerignore

node_modules
build
dist
config
docs
*.log
.git
.vscode

然后构建镜像: docker build -t <your image name> -f <Dockerfile (if omitted uses local folder .Dockerfile> <path to code your code>

一旦构建完成,就可以像普通图像一样运行它 - 因为一切都已经在其中了。

【讨论】:

    猜你喜欢
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多