简体   繁体   English

无法连接到Docker上的localhost

[英]Can't connect to localhost on Docker

I got this error suddenly. 我突然收到此错误。 Before getting this error I could connect. 在收到此错误之前,我可以连接。

$ curl localhost:3000
curl: (7) Failed to connect to localhost port 3000: Connection refused

My environments are below. 我的环境在下面。

OS:macOS Sierra 10.12.6 Docker version 18.06.1-ce, build e68fc7a 操作系统:macOS Sierra 10.12.6 Docker版本18.06.1-ce,内部版本e68fc7a

docker-compose.yml 泊坞窗,compose.yml

version: "3"

services:
  web:
    build: web
    ports:
      - "3000:3000"
    environment:
      - "DATABASE_HOST=db"
      - "DATABASE_PORT=5432"
      - "DATABASE_USER=********"
      - "DATABASE_PASSWORD=********"
    links:
      - db
    volumes:
      - "./app:/app" #共有フォルダの設定
    stdin_open: true

  db:
    image: postgres:10.1
    ports:
      - "5432:5432"
    environment:
      - "POSTGRES_USER=********"
      - "POSTGRES_PASSWORD=********"

Dockerfile Dockerfile

FROM ruby:2.5.0

RUN apt-get update && apt-get install -y build-essential libpq-dev postgresql-client
RUN gem install rails
RUN mkdir /app
WORKDIR /app

If you have some suggestion to solve this please tell me. 如果您有解决此问题的建议,请告诉我。 Thanks. 谢谢。

you should specify your command for running application like: bundle exec rails s -p 3000 -b '0.0.0.0' which run your server on port 3000 and bind it to local network 0.0.0.0 . 您应该指定用于运行应用程序的命令,例如: bundle exec rails s -p 3000 -b '0.0.0.0'它将在端口3000上运行服务器并将其绑定到本地网络0.0.0.0 so you should write it in your Dockerfile in the last line: 所以您应该在最后一行的Dockerfile中编写它:

RUN bundle exec rails s -p 3000 -b '0.0.0.0'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM