Docker Compose无法访问本地主机

时间:2019-10-02 13:57:33

标签: ruby-on-rails docker nginx docker-compose

我目前在Ruby on Rails中使用docker-compose并遇到了严重的问题。我无法在Chrome搜索栏上输入localhost:3000来访问本地主机。这是docker-compose.yml

version: '3.6'
services:
  rails:
    build:
      context: .
      dockerfile: ./docker/rails/Dockerfile
    volumes:
      - .:/code
    environment:
      RAILS_ENV: development
    restart: always
    command: bundle exec rails s -b '0.0.0.0'
  nginx:
    build: ./docker/nginx
    restart: always
    ports:
      - "3000:80"
    depends_on:
      - rails

这是docker ps

的输出
CONTAINER ID        IMAGE                       COMMAND                  CREATED              STATUS              PORTS                  NAMES
abb871c7091e        _ex_nginx              "nginx -g 'daemon of…"   About a minute ago   Up About a minute   0.0.0.0:3000->80/tcp   mates_ex_nginx_1
7507ee9496c4        _ex_rails              "./docker-rails-entr…"   About a minute ago   Up About a minute                          mates_ex_rails_1

cat /etc/hosts的结果如下。

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
255.255.255.255 broadcasthost

127.0.0.1       localhost
::1             localhost

# Added by Docker Desktop
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section

在docker日志上,它说Rails正在0.0.0.0:3000上运行。

rails_1  | * Listening on tcp://0.0.0.0:3000

任何答案将不胜感激!预先谢谢你。

0 个答案:

没有答案