docker - 流浪码头供应商 - 无法卷曲到本地主机
问题描述
我正在尝试使用 Vagrant 和 Docker 模拟我们的微服务框架。我有一个用作 API 网关的 Vagrant VM。在Vagrantfile
我使用 Docker 配置来设置 Kong。我的目标是使用 cURL 在配置中引导必要的 Kong 服务。
我的Vagrantfile
:
Vagrant.configure("2") do |config|
config.vm.hostname = 'apigateway'
config.vm.box = "centos/7"
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "192.168.110.110"
config.vm.synced_folder ".", "/vagrant"
config.vm.provision "docker" do |docker|
config.vm.provision "shell" do |sh|
docker.pull_images "postgres:9.6"
docker.pull_images "kong"
docker.run "postgres:9.6",
image: "postgres:9.6",
args: "--name kong-db --network='host' -p 5432:5432 -e 'POSTGRES_USER=kong' -e 'POSTGRES_DB=kong' -e 'POSTGRES_PASSWORD=kong'",
auto_assign_name: false
sh.inline = "firewall-cmd --permanent --add-port=5432/tcp"
sh.inline = "firewall-cmd --reload"
docker.run "kong-migrations",
image: "kong",
cmd: "kong migrations bootstrap",
args: "--name kong-migrations --network='host' -e 'KONG_DATABASE=postgres' -e 'KONG_PG_HOST=localhost' -e 'KONG_PG_USER=kong' -e 'KONG_PG_PASSWORD=kong' -e 'KONG_PG_DATABASE=kong'",
auto_assign_name: false,
restart: "on-failure"
docker.run "kong",
image: "kong",
args: "--name kong --network='host' -p 8000:8000 -p 8443:8443 -p 8001:8001 -p 8444:8444 -e 'KONG_DATABASE=postgres' -e 'KONG_PG_HOST=localhost' -e 'KONG_PG_USER=kong' -e 'KONG_PG_PASSWORD=kong' -e 'KONG_PG_DATABASE=kong' -e 'KONG_ADMIN_LISTEN=127.0.0.1:8001, 127.0.0.1:8444 ssl'",
auto_assign_name: false
sh.inline = "firewall-cmd --permanent --add-port=8000/tcp"
sh.inline = "firewall-cmd --permanent --add-port=8001/tcp"
sh.inline = "firewall-cmd --permanent --add-port=8443/tcp"
sh.inline = "firewall-cmd --permanent --add-port=8444/tcp"
sh.inline = "firewall-cmd --reload"
###### The cURL shell scripts that raised the errors #######
sh.inline = "docker exec kong curl -i -X POST --url http://localhost:8001/services/ --data 'name=admin-api' --data 'url=http://localhost:8001'"
sh.inline = "docker exec kong curl -i -X POST --url http://localhost:8001/services/admin-api/routes --data 'path=/admin-api'"
sh.inline = "docker exec kong curl -i -X POST --url http://localhost:8001/services/admin-api/plugins --data 'name=jwt'"
####### --End of cURL scripts #####
end
end
end
问题是 cURL 脚本引发了错误
default: curl: (7) Failed to connect to localhost port 8001: Connection refused
但是,当我在虚拟机中执行 cURL 脚本后,操作会成功vagrant ssh
,即
docker exec kong curl -i -X POST --url http://localhost:8001/services/ --data 'name=admin-api' --data 'url=http://localhost:8001'
我尝试使用 VM IP192.168.110.110
而不是,localhost
我得到了Connection reset by peer
.
这个设置有什么问题?应该做什么?
解决方案
如果在设置后直接与 ssh 连接时它正在工作,那么我的猜测是你在 vagrantfile 中的 curl 完成得太快了。
当您进行 curl 时,您的服务器可能尚未启动。如果你在 curl 之前稍等片刻会发生什么?行得通吗?
推荐阅读
- javascript - Aframe 射线投射器 交叉点
- angular - 以角度处理全局字符串的好习惯是什么?
- c++ - 对参数包的每个值应用函数并检查返回值
- google-api - 如何根据 gsuite appID 获取应用描述
- java - 如何避免内部类使用元素数组?
- php - 无法 laravel gulp 命令
- elasticsearch - Elasticsearch 通配符可以正常工作,但 query_string 不能
- rx-java - 如何... Rxjava 在获取计数时可流动的过程
- python - 将分类列添加到预测模型中
- git - 如何在 Visual Studio Code 中更改 Git 区域设置?