我正在使用以下docker版本...
localhost:client davea$ docker -v
Docker version 19.03.5, build 633a0ea
我有以下Dockerfile
FROM node:10-alpine AS alpine
WORKDIR /app
# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json /app/
## install only the packages defined in the package-lock.json (faster than the normal npm install)
RUN npm install
# Copy the contents of the project to the image
COPY . .
# Run 'npm start' when the container starts.
CMD ["npm", "run", "start"]
然后我像这样构建并运行映像...
localhost:client davea$ docker build --tag client:1.0 .
Sending build context to Docker daemon 2.317MB
Step 1/6 : FROM node:10-alpine AS alpine
---> 34a10d47f150
Step 2/6 : WORKDIR /app
---> Using cache
---> c039266280ac
Step 3/6 : COPY package*.json /app/
---> Using cache
---> 69938dc0b9db
Step 4/6 : RUN npm install
---> Using cache
---> 6030b0efcbaf
Step 5/6 : COPY . .
---> Using cache
---> 0e804956b8f1
Step 6/6 : CMD ["npm", "run", "start"]
---> Using cache
---> 4367bce40216
Successfully built 4367bce40216
Successfully tagged client:1.0
localhost:client davea$ docker run --publish 3001:3000 --detach --name client client:1.0
97aa49d63d4014f62728187c56037d77b9de0fcf84bcca3114b585edb0650a95
但是,当我尝试访问我的应用程序时,尽管我尝试在指定的端口上进行连接,但我还是拒绝了连接...
localhost:client davea$ wget http://localhost:3001
--2020-03-31 20:44:20-- http://localhost:3001/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:3001... failed: Connection refused.
Connecting to localhost (localhost)|127.0.0.1|:3001... failed: Connection refused.
我还能如何找出这里出了什么问题?我的Docker文件构建中没有发现任何明显的缺陷。
编辑:这是在已停止的容器上运行“ docker日志”的输出...
> client@0.1.0 start /usr/src/app
> react-scripts start
[HPM] Missing "target" option. Example: {target: "http://www.example.org"}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! client@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the client@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-04-01T02_04_40_090Z-debug.log
答案 0 :(得分:0)
您必须像这样在dockerfile中公开端口;
...
EXPOSE 3000
CMD ["npm", "run", "start"]