所以,已经过去了几周了,经过一些成功的尝试,每当我尝试连接到Docker容器时,我都会得到“此连接已重置”。 这是我的Docker-compose
version: "3.3"
services:
db:
image: 'postgres:10-alpine'
container_name: 'postgres'
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=4321
- POSTGRES_DB=twr
volumes:
- twrdb:/var/lib/postgresql/data
backend:
build: ./backendtwr
volumes:
- ./backendtwr:/app
ports:
- 4000:8080
links:
- db
frontend:
build: ./frontendtwr
volumes:
- ./frontendtwr:/app
ports:
- 4001:4200
links:
- backend
还有我的前端Docker文件
#base image
FROM node:10.16.0
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package.json /app
RUN npm install
RUN npm install d3
COPY . .
EXPOSE 4200
# start app
CMD ng serve
我添加了npm install d3,因为它拒绝从我的package.json安装d3。顺便说一句,大约在添加该行时,我无法从主机上查看我的应用程序;错误
This site can’t be reachedThe connection was reset.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_RESET
从我的Chrome浏览器
有关其他信息:这是后端的dockerfile,该文件可以在我的浏览器上运行,没有任何问题。
#base image
FROM node:8.12.0
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package.json /app
RUN npm install
COPY . .
EXPOSE 8080
# start app
CMD npm run start:dev
答案 0 :(得分:0)
version: "3.3"
services:
db:
image: 'postgres:10-alpine'
container_name: 'postgresnew'
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=4321
- POSTGRES_DB=twr
volumes:
- pgdata:/var/lib/postgresql/data
frontend:
build: ./frontendtwr
ports:
- 4001:4200
volumes:
- ./frontendtwr:/app
- /app/node_modules/
backend:
build: ./backendtwr
ports:
- 4000:8080
volumes:
- ./backendtwr:/app
- /app/node_modules/
env_file:
- .env
volumes:
pgdata:
此问题已解决... 就像@DavidMaze所说的,我使用了错误的音量块。