我目前在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
任何答案将不胜感激!预先谢谢你。