我基于nodejs创建了一个docker-container。但是,它似乎运行良好,但是localhost:8080和localhost:8443以及localhost无法连接。另外,使用curl的连接会产生以下消息:
$ curl -vvv localhost:8080
* Trying ::1:8080...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.67.0
> Accept: */*
>
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer
$ curl -vvv localhost:8443
* Trying ::1:8443...
* TCP_NODELAY set
* Connected to localhost (::1) port 8443 (#0)
> GET / HTTP/1.1
> Host: localhost:8443
> User-Agent: curl/7.67.0
> Accept: */*
>
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer
这是docker-compose.yml
version: "2"
services:
app:
container_name: app_test
restart: always
build: .
ports:
- "8080:8080"
- "8443:8443"
这是Dockerfile
FROM node:10.12.0
WORKDIR /usr/src/app
COPY package.json ./
RUN npm install
COPY . .
EXPOSE 80 # I try 3000, 8080 instead 80
CMD [ "node", "app.js" ]
这是docker ps
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
735fba0a6ff5 IMAGE_NAME "node app.js" 46 seconds ago Up 45 seconds 0.0.0.0:8080->8080/tcp, 80/tcp, 0.0.0.0:8443->8443/tcp app_test
curl和浏览器均未运行。我该怎么办?
(我很尴尬,因为我不会说英语。请理解。)
答案 0 :(得分:1)
version: "2"
services:
app:
container_name: app_test
restart: always
build: .
ports:
- "8080:3000"
- "8443:8443"
如果您要在localhost:8080上访问您的应用, 这应该工作。节点应用程序在标准端口3000上提供。
所以基本上:
{端口主机} : {端口实际上在容器内部运行}