S Andrew
S Andrew

Reputation: 7208

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

I have 3 linux machine and I have made one machine as manager and other two as worker1 and worker2. So lets say I have docker image and I have tested this on manager , it works fine. Now I want to deploy the same on all the nodes. For this, I first pushed the image to docker hub and then when its available on docker hub, I then ran the command

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

This then started the deployment on all the worker nodes and after some time, workers were running the deployed docker image. 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.?

Next I want to know, when I start my docker image I use -v option to give path to my mount directory. How can I use this -v to option during the deployment process?

Upvotes: 2

Views: 3238

Answers (1)

Fendi jatmiko
Fendi jatmiko

Reputation: 2895

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.?

quote from @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

i think this is quite similar with this

Upvotes: 1

Related Questions