繁体   English   中英

yarn 不会在 docker 容器中创建 node_modules 文件夹

[英]yarn doesn't create node_modules folder in docker container

我正在尝试使用 dockerfile 和 docker_compose 构建一个应用程序。 一切似乎都没问题,直到涉及到yarn命令,该命令不创建 node_module 也不安装依赖项。

docker-compose 文件:

version: '2'

services:
  mdisassistant:
    env_file: .env
    build:
      context: .
      args:
        - APP_NAME=${APP_NAME}
        - APP_USER=app
    ports:
      - ${APP_PORT}:${APP_PORT}

Dockerfile:

FROM node:10.15.2-alpine

ARG APP_NAME
ARG APP_USER

RUN adduser -D -s /bin/false -h /home/$APP_USER $APP_USER $APP_USER

ENV HOME=/home/$APP_USER
WORKDIR $HOME/$APP_NAME
COPY . .
RUN chown $APP_USER:$APP_USER -R $HOME
USER $APP_USER

RUN whoami

RUN yarn install

RUN ls -la 
RUN pwd

RUN yarn build

CMD ["node", "./dist/index.js"]

输出:

Building mdisassistant
Step 1/15 : FROM node:10.15.2-alpine
---> 072459fe4d8a
Step 2/15 : ARG APP_NAME
---> Using cache
---> 4c30b08b312d
Step 3/15 : ARG APP_USER
---> Using cache
---> 9631ef748cd7
Step 4/15 : RUN adduser -D -s /bin/false -h /home/$APP_USER $APP_USER $APP_USER
---> Using cache
---> f5d045ca5282
Step 5/15 : ENV HOME=/home/$APP_USER
---> Using cache
---> 32c4f9457b9e
Step 6/15 : WORKDIR $HOME/$APP_NAME
---> Using cache
---> a8d71a9f563f
Step 7/15 : COPY . .
---> d4ef17f02a9f
Step 8/15 : RUN chown $APP_USER:$APP_USER -R $HOME
---> Running in f6c194316e12
Removing intermediate container f6c194316e12
---> f6742a0c10df
Step 9/15 : USER $APP_USER
---> Running in ec22ed655aa5
Removing intermediate container ec22ed655aa5
---> af800732027d
Step 10/15 : RUN whoami
---> Running in ba9fa81a95a3
app
Removing intermediate container ba9fa81a95a3
---> ebf0f6a4f8a7
Step 11/15 : RUN yarn install
---> Running in 4d5e76dd1508
yarn install v1.13.0
[1/4] Resolving packages...
[2/4] Fetching packages...
Removing intermediate container 4d5e76dd1508
---> 1785eec9829e
Step 12/15 : RUN ls -la
---> Running in b0f3f1b1e5fc
total 92
drwxr-sr-x    1 app      app           4096 Mar 21 02:52 .
drwxr-sr-x    1 app      app           4096 Mar 21 02:52 ..
-rw-r--r--    1 app      app           1610 Mar 21 02:05 .dockerignore
-rw-r--r--    1 app      app             62 Mar 21 00:56 .env.example
drwxr-xr-x    1 app      app           4096 Mar 21 02:52 .git
-rw-r--r--    1 app      app           1610 Mar 20 23:56 .gitignore
-rw-r--r--    1 app      app            333 Mar 21 02:52 Dockerfile
-rw-r--r--    1 app      app           1060 Mar 20 23:56 LICENSE
-rw-r--r--    1 app      app            681 Mar 20 23:56 README.md
-rw-r--r--    1 app      app            280 Mar 21 02:35 docker-compose.yml
-rw-r--r--    1 app      app            614 Mar 21 01:57 package.json
drwxr-xr-x    1 app      app           4096 Mar 21 01:05 src
-rw-r--r--    1 app      app          44193 Mar 21 01:20 yarn.lock
Removing intermediate container b0f3f1b1e5fc
---> eb6fbee4548f
Step 13/15 : RUN pwd
---> Running in 92b3d6d20201
/home/app/mdisassistant
Removing intermediate container 92b3d6d20201
---> 853d9879da99
Step 14/15 : RUN yarn build
---> Running in 205ef8079386
yarn run v1.13.0
$ ncc build src/index.js -o dist -m
/bin/sh: ncc: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: Service 'mdisassistant' failed to build: The command '/bin/sh -c yarn build' returned a non-zero code: 1

如何解决这个问题?

您可以尝试不创建用户吗

FROM node:10.15.2-alpine

WORKDIR /app
COPY package.json .

RUN whoami

RUN yarn install
RUN ls -la 
RUN pwd


COPY . .
RUN yarn build

CMD ["node", "./dist/index.js"]

问题出在我用来构建 docker 容器的 docker 和 OS 版本中。

我使用 docker 版本 18.x 运行 docker docker-compose ,操作系统是 Deepin 15.11 我切换到 EleebtaryOS 版本 5.1.2 Hera 并安装了 docker 版本 19.03.6,现在一切正常。

我不知道为什么在 Deepin OS 中会发生这种情况。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM