我有3个Docker容器,一个运行php
,另一个serf
和一个运行exec
的hashicorp。
我想使用php serf
函数调用serf event
二进制文件来启动version: '2'
services:
web:
restart: always
image: `alias`/nginx-pagespeed:1.11.4
ports:
- 80
volumes:
- ./web:/var/www/html
- ./conf/nginx/default.conf:/etc/nginx/conf.d/default.conf
links:
- php
environment:
- SERVICE_NAME=${DOMAIN}
- SERVICE_TAGS=web
php:
restart: always
image: `alias`/php-fpm:7.0.11
links:
- serf
external_links:
- mysql
expose:
- "9000"
volumes:
- ./web:/var/www/html
- ./projects:/var/www/projects
- ./conf/php:/usr/local/etc/php/conf.d
serf:
restart: always
dns: 172.17.0.1
image: `alias`/serf
container_name: serf
ports:
- 7496:7496
- 7496:7496/udp
command: agent -node=${SERF_NODE} -advertise=${PRIVATE_IP}:7496 -bind=0.0.0.0:7496
在我的码头作品中,我写了
exec('serf serf event "test"')
我想象我会做一些像php serf
这样的事情,其中func createButton () {
var setx = 50
var sety = 100
var delay = 0.4
var wordsInCharacters = [String]()
for letter in "RAILROAD".characters{
wordsInCharacters.append("\(letter)")
}
while wordsInCharacters.count > 0 {
let randomIndex = Int(arc4random_uniform(UInt32(wordsInCharacters.count)))
// Creating the buttons
let button = SpringButton()
button.frame = CGRect(x: setx, y: sety, width: 64, height: 64)
button.setTitle( "\(wordsInCharacters[randomIndex])", for: .normal)
button.setTitleColor(UIColor.white, for: .normal)
button.backgroundColor = UIColor.gray
button.titleLabel?.font = UIFont(name: "HelveticaNeue", size: 30)
// Add animation
UIView.animate(withDuration: 1, delay: delay, options: .curveEaseInOut, animations: {
self.view.addSubview(button)
}, completion: nil)
if setx <= 200 {
setx += 100
}
else{
setx = 50
sety += 100
}
wordsInCharacters.remove(at: randomIndex)
delay += 0.2
}
}
是容器的主机名。
或者也许有人可以通过其他方法了解如何使用此方法设置?
答案 0 :(得分:3)
&#34;链接&#34;容器允许容器之间的网络级别发现。使用docker网络,链接的功能现在被认为是遗留的,并且不再是真正推荐的。要在另一个容器中运行命令,您需要在目标容器上打开网络API功能(例如,对目标容器的基于REST的http请求),或者您需要将主机公开给源容器所以它可以对目标容器运行docker exec
。
后者要求您在源容器中安装docker客户端,然后使用主机上的开放端口或在容器中安装/var/run/docker.sock
来公开服务器。由于这允许容器在主机上具有root访问权限,因此除了管理容器之外的其他任何操作都不建议使用,否则您将信任直接在主机上运行的代码。
我能想到的另一个选择是删除具有共享卷的容器之间的隔离。
理想的解决方案是使用消息队列服务,允许多个工作人员按自己的进度启动和处理请求。源容器向队列发送请求,目标容器在其运行时侦听请求。这也允许系统在工人当前停机时继续,活动只是排队。