Docker Swarm- 如何将本地 docker 映像从管理器部署到所有工作节点

Docker Swarm- How to deploy a local docker image from manager to all worker nodes

我有 3 台 linux 机器,我将一台机器设为 manager,另外两台设为 worker1worker2。所以假设我有 docker 图像并且我已经在 manager 上测试过它,它工作正常。现在我想在所有节点上部署相同的东西。为此,我首先将图像推送到 docker 集线器,然后当它在 docker 集线器上可用时,我然后 运行 命令

sudo docker service create --name <name> --mode global <docker-name/image-name>

然后开始在所有工作节点上部署,一段时间后,工作人员 运行 已部署 docker 映像。现在我想知道是否可以在工作节点上部署图像而不将该图像推送到 docker 集线器上。所以我在管理器节点上有一个本地可用的 docker 图像,我只希望将该图像部署在工作节点上。我怎样才能做到这一点?

接下来我想知道,当我启动我的 docker 图像时,我使用 -v 选项来提供我的挂载目录的路径。如何在部署过程中使用此 -v 选项?

Now I want to know is it possible to deploy the image on the worker nodes without pushing that image on docker hub. So I have a docker image locally available with me on manager node and I just want that Image to be deployed on worker nodes. How can I achieve this.?

@BMitch 引述:

The manager node doesn't share out the local images from itself. You need to spin up a registry server .

#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

我认为这与

非常相似