您所指的PID可能是模棱两可的.可以是容器名称空间或主机的PID. 如果要从容器外部引用进程,则需要使用主机的PID,而不要使用容器中出现的PID,因为它位于单独的进程名称空间中.参见例如 the-curious-case-of-pid-namespaces 容器可能能够识别主机和PID本身(毕竟它应该是沙箱) IP地址将相对于内部网络(通常) 主机名将通过DNS查找(通常) 现在URI是指端口而不是PID,因此URI在这里不合适. PID @ HOST可能是一个明智的表示法,但请注意与user @ host混淆.除了容器和容器ID之外,还有其他更方便的方式来标识处理资源,例如状态集 This is a general question but for arguments sake you may and assume we have a collection of processes communicating via a combination of AMQP and HTTP. There are two specific cases to consider.The easy one:Q) If A sends a message to B how does B identify the location of A to send a reply.A) A must tell B where to send it somehow (exchange for AMQP, URL for http)The harder ones:Q) How does a monitoring process send a message to A (where something else has prompted this desire - e.g. B says A sent me a bad request)Q) How does a monitoring process kill or restart A.This could be something like kill a host+pid or a pod or a pod+container (see for example kubernetes restart container within pod) You might wish to restart an entire service or some subset of the processes that are providing that service.Now you can assign a UUID yourself but you need a table to map it.This may have multiple columns but sometimes a single URI (or URI like thing) is useful for example as a "originated from/reply to" address.Another way to view this question.In the old days it was easy to identify a process.A hostname (or IP address) + a PID was sufficientThen came virtualisation the IP address identifies the virtual network port assigned to the VM and the PID identifies the process within it.A hostname and IP address are still sufficient.Sometimes you need the vhost as well (though I was never clear why)Now adding containers to the mix a container doesn't necessarily have a IP address of its own. A host+pid can identify the containerBut you might not know the host if you are running kubernetes or docker swarm.Now we don't talk about processes so much anymore as about services.It used to be enough to identify a service using a hostname (or IP address) and a port (YMMV - Can an IP address and a port number together uniquely identify a process ID?).Now we have load balancers and other tricks (e.g. caching proxies) to redirect messages to something else that actually provides a service.A service might be provided by a container or a pod containing several containers in which case you may want to address the pod or the container.See for example kubernetes restart container within podIt looks like container names are unique per docker instance but not beyond that.So there a few different ways you might want to address a message.Is there a good standard way of doing this?To my mind the obvious thing to use is a URI (but I could be wrong). Are there recommended URI forms to handle all possible cases?(obviously we have procotocl://host:port/ for the easy cases) 解决方案 After some consideration I believe host+pid is still sufficient (but not necessarily the best way) to identify a process providing you are mindful of the following:whose PID you mean could be ambiguous.It could be the PID of the container's namespace or the host.If you are referring to the process from outside the container you need to use the PID of the host not the PID as it appears inside the container as this is in a separate process namespace. See for example the-curious-case-of-pid-namespacesThe container may evem be able to identify the host and PID itself (after all it is supposed to be a sandbox)IP addresses will be relative to the internal network (as normal)hostnames will go via DNS lookup (as normal)Now a URI refers to a port not a PID so a URI is not appropriate here. PID@HOST is probably a sensible notation but beware confusion with [email protected] addition to container and pod Ids there are other more convenient ways to identify a processing resource such as stateful sets 这篇关于如何在容器化世界中独特地解决“过程"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-26 18:05