我正在尝试将一个示例react.js应用容器化到Docker内部。
我的docker文件如下,我在项目的工作目录中
FROM node:10-alpine
RUN mkdir -p /var/tmp/thermodocker && chown -R root:root /var/tmp/thermodocker
WORKDIR /var/tmp/thermodocker
COPY * ./
USER root
RUN [ "npm", "install","--python","python2" ]
EXPOSE 3000
CMD [ "npm", "run" ]
我可以成功创建图像
[root@******]# docker build -t thermo-api .
...
Successfully built c6697819c3e1
Successfully tagged thermo-api:latest
但是,当我想运行该应用程序时,它并不会显示为正在运行的Docker映像
[root@******]# docker run -d -p 3000:3000 --name thermo-api-app thermo-api
51b873637ac12ee2a89d075edf1953c29b41826b6b3847659d7763d42516916a
INFO[2020-07-29T01:01:30.555414295Z] shim containerd-shim started address="/containerd-shim/moby/51b873637ac12ee2a89d075edf1953c29b41826b6b3847659d7763d42516916a/shim.sock" debug=false pid=8021
[root@********]# INFO[2020-07-29T01:01:31.081201052Z] shim reaped id=51b873637ac12ee2a89d075edf1953c29b41826b6b3847659d7763d42516916a
INFO[2020-07-29T01:01:31.088559217Z] ignoring event module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"
[root@******]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@thermo-breast-cancer-devvm1 thermo-api]#
我不确定我在哪里做错了吗?
[PS:] 根据评论,我将CMD更改为
RUN [ "npm", "install","--python","python2" ]
但是我无法建立图像
Step 6/8 : RUN [ "npm", "install","--python","python2" ]
---> Running in 77155726f35e
INFO[2020-07-29T01:35:38.577900480Z] shim containerd-shim started address="/containerd-shim/moby/77155726f35ed6f7464d6e801d767221d62e0e31fd7e342835b6d861e3694b57/shim.sock" debug=false pid=8717
npm ERR! code EAI_AGAIN
npm ERR! errno EAI_AGAIN
npm ERR! request to https://registry.npmjs.org/python2 failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org registry.npmjs.org:443
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-07-29T01_35_44_304Z-debug.log
INFO[2020-07-29T01:35:44.354721669Z] shim reaped id=77155726f35ed6f7464d6e801d767221d62e0e31fd7e342835b6d861e3694b57
INFO[2020-07-29T01:35:44.361799117Z] ignoring event
答案 0 :(得分:0)
Dockerfile中只能有一条CMD
指令。如果您列出多个CMD
,则只有最后一个CMD
才会生效。
您可能希望将npm install
用作RUN
指令,而不是CMD
。
按原样,它只做npm run
却从未做过npm install
,因此很可能会立即退出并出现错误。