Docker:Swarm worker节点没有find本地构build的映像

也许我错过了一些东西,但我做了一个当地的docker形象。 我有一个3节点的群集,并运行。 两名工人和一名经理。 我使用标签作为约束。 当我通过约束向其中一名工作人员启动一项服务时,如果该图像是公开的,则完美工作。

也就是说,如果我这样做:

docker service create --name redis --network my-network --constraint node.labels.myconstraint==true redis:3.0.7-alpine 

然后redis服务被发送到其中一个工作节点,并且function齐全。 同样,如果我运行我的本地生成的图像没有约束,因为我的经理也是一个工人,它被安排到经理,并运行得很好。 但是,当我添加约束失败的工人节点,从docker service ps 2l30ib72y65h我看到:

 ... Shutdown Rejected 14 seconds ago "No such image: my-customized-image" 

有没有办法让工作人员能够访问群pipe理器节点上的本地映像? 它是否使用了可能不能打开的特定端口? 如果没有,我该怎么做 – 运行一个本地存储库?

pipe理器节点不会从本身共享本地图像。 您需要启动registry服务器(或用户hub.docker.com)。 为此所需的努力并不是很重要:

 # first create a user, updating $user for your environment: if [ ! -d "auth" ]; then mkdir -p auth fi chmod 666 auth/htpasswd docker run --rm -it \ -v `pwd`/auth:/auth \ --entrypoint htpasswd registry:2 -B /auth/htpasswd $user chmod 444 auth/htpasswd # then spin up the registry service listening on port 5000 docker run -d -p 5000:5000 --restart=always --name registry \ -v `pwd`/auth/htpasswd:/auth/htpasswd:ro \ -v `pwd`/registry:/var/lib/registry \ -e "REGISTRY_AUTH=htpasswd" \ -e "REGISTRY_AUTH_HTPASSWD_REALM=Local Registry" \ -e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" \ -e "REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/var/lib/registry" \ registry:2 # then push your image docker login localhost:5000 docker tag my-customized-image localhost:5000/my-customized-image docker push localhost:5000/my-customized-image # then spin up the service with the new image name # replace registryhost with ip/hostname of your registry Docker host docker service create --name custom --network my-network \ --constraint node.labels.myconstraint==true --with-registry-auth \ registryhost:5000/my-customized-image 

对我来说,这一步一步的buide,这是不安全的:

 # Start your registry $ docker run -d -p 5000:5000 --name registry registry:2 # Tag the image so that it points to your registry $ docker tag my_existing_image localhost:5000/myfirstimage # Push it to local registry/repo $ docker push localhost:5000/myfirstimage # For verification you can use this command: $ curl -X GET http://localhost:5000/v2/_catalog # It will print out all images on repo. # On private registry machine add additional parameters to enable insecure repo: ExecStart=/usr/bin/dockerd --insecure-registry IP_OF_CURRENT_MACHINE:5000 # Flush changes and restart Docker: $ systemctl daemon-reload $ systemctl restart docker.service # On client machine we should say docker that this private repo is insecure, so create or modifile the file '/etc/docker/daemon.json': { "insecure-registries":["hostname:5000"] } # Restart docker: $ systemctl restart docker.service # On swarm mode, you need to point to that registry, so use host name instead, for example: hostname:5000/myfirstimage 

必须将图像下载到每个节点上的本地caching中。 原因是,如果只将所有图像存储在一个节点上,并且该节点停止运行,那么swarm将无法在其他节点上产生新的任务(容器)。

我个人只是在开始服务之前,把每个节点上的所有图像的副本。 这可以在bash脚本或Makefile中完成(例如,下面)

 pull: @for node in $$NODE_LIST; do OPTS=$$(docker-machine config $$node) set -x docker $$OPTS pull postgres:9.5.2 docker $$OPTS pull elasticsearch:2.3.3 docker $$OPTS pull schickling/beanstalkd docker $$OPTS pull gliderlabs/logspout etc ... set +x done