1

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?

S Andrew
  • 5,592
  • 27
  • 115
  • 237
  • Possible duplicate of [Docker: Swarm worker nodes not finding locally built image](https://stackoverflow.com/questions/39370925/docker-swarm-worker-nodes-not-finding-locally-built-image) – yamenk Jan 10 '18 at 08:20

1 Answers1

1

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

Fendi jatmiko
  • 2,567
  • 1
  • 9
  • 15
  • In the last command `docker service create...` what does `--network my-network` and `--constraint` means what do I have to put in these flags. Can you please explain this command.? Thanks – S Andrew Jan 10 '18 at 09:31
  • the `--network` is docker network type that you wanna use,, check your available network with `docker network ls` more about docker network https://docs.docker.com/engine/reference/commandline/network_create ... as of the `--constraint` is a type of node filtering to ensure two containers are not living on the same node.. https://docs.docker.com/swarm/scheduler/filter/ – Fendi jatmiko Jan 10 '18 at 09:59
  • Thanks. As I have mentioned that I am using raspberry pi so running the command `docker run -d -p 5000:5000 --restart=always --name registry...` gave me error because this is not supported for raspberry pi. So I used [this](https://hub.docker.com/r/budry/registry-arm/). This works fine. I have even pushed my image to the registry when I do `curl localhost:5000/v2/_catalog` on the manager node, I get the list of images but when I do same on the worker node, it give me error `Failed to connect to localhost:5000`. Is there anything which I am missing.And because of this I am not able to deploy it – S Andrew Jan 10 '18 at 10:04
  • wait, have you even mention *raspberry pi* before,,?i thought you were just saying 3 linux machines.. – Fendi jatmiko Jan 10 '18 at 10:21
  • I am so sorry about that. If you have idea about it, can you please explain it.? – S Andrew Jan 10 '18 at 10:23
  • take a look at this issue : https://github.com/docker/swarmkit/issues/1429 – Fendi jatmiko Jan 10 '18 at 11:06