我如何正确地将Nest-Js / Angular docker-compose映像连接到主机?

问题描述 投票:0回答:1

所以,已经过去了几周了,经过一些成功的尝试,每次尝试连接到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
docker docker-compose
1个回答
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所说的,我使用了错误的音量块。

© www.soinside.com 2019 - 2024. All rights reserved.