2
我的本地安裝的docker無法訪問其他端口。Docker,連接拒絕其他所有正在運行的服務
這是我docker-compose.yml
文件:
db:
image: library/mysql:5.6
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
expose:
- "3306"
ports:
- "3306:3306"
mailcatcher:
image: yappabe/mailcatcher
ports:
- "1025:1025"
- "1080:1080"
rails-app:
build: .
dockerfile: "Dockerfile"
environment:
RAILS_ENV: development
links:
- mailcatcher
- db
command: bundle exec rails server -p 3005 -b '0.0.0.0'
volumes:
- ".:/home/app"
volumes_from:
- bundle
expose:
- "3005"
ports:
- "3005:3005"
這是mailcatcher config/environments/development.rb
的配置:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { address: "localhost", port: 1025 }
這是我如何運行Rails應用程序:
docker-compose run --service-ports rails-app
這是我運行時看到的是什麼docker ps
:
> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1fa8ac2ad8fd pmt_rails-app "bundle exec rails se" 5 seconds ago Up 3 seconds 0.0.0.0:3005->3005/tcp pmt_rails-app_run_1
4f65bb2fc9ac yappabe/mailcatcher "/run.sh" About an hour ago Up About an hour 0.0.0.0:1025->1025/tcp, 0.0.0.0:1080->1080/tcp pmt_mailcatcher_1
cfb364ee569f library/mysql:5.6 "docker-entrypoint.sh" About an hour ago Up About an hour 0.0.0.0:3306->3306/tcp pmt_db_1
這是我所得到的,當Rails應用程序試圖發送電子郵件:當我嘗試用另一個rails server
了在另一個端口運行連接
Errno::ECONNREFUSED: Connection refused - connect(2) for "localhost" port 1025
from /usr/local/lib/ruby/2.3.0/net/smtp.rb:542:in `initialize'
我得到同樣的錯誤。
我在Mac OSX上使用Docker-beta。
你救了我的命! –
很高興我可以幫助:) – lsowen
2生命,並計數! – unmultimedio