Docker Swarm Service Fails But Container Run Works

Does anyone know why I can not create a docker service with the busybox image at https://docs.docker.com/samples/library/busybox/

I am able to run the image if I do:
sudo docker run -ti busybox /bin/sh

But if I create a service with the image it just continuously redeploys new containers and there are no logs in the containers if I do:
sudo docker service logs -f

or if I do the same for the servicename.

Is there something Im missing here? Are there some containers you can run but not deploy a service of?

I have the latest version of docker swarm running on ubuntu 18.04 gcloud vms and I am able to deploy other services such as the redis 3.0.6 shown in the docker service create documentation.

Did you check docker service ps {servicename} to see if something went wrong during scheduling?

I finally figured it out. There were no error logs because there were no errors. If you run a docker container service with an empty ubuntu or busybox or a simple helloworld app that closes after running it just creates the container runs the app(if it exists) and the closes the container as soon as the app finishes executing.

Did this as a work around:

sudo docker service create ubuntu /bin/sh -c `“while true; do echo Hello; sleep 2; done”

Tested it and it works, the bash script keeps the containers open so I can use my ubuntu image to install networking tools for general debugging.

But, you could write your own Dockerfile that installs the networking tools, build that image and then start that one instead. Starting a clean ubuntu just to get into it and manually install stuff is not the most efficient way to do it imho.

Yea thanks, ultimately that is my goal! Im new to all this so im taking baby steps here, but you’re right.

Baby steps of a long and hard way around… that is the question. :wink:
If you know how to install the tools you want, creating a Dockerfile that does the provisioning for you is really easy.

And alos, take a look in the hub. Quite often, there is already maintained images that does a lot of this for you or that you can imitate/copy to learn. Like https://hub.docker.com/r/ianneub/network-tools/dockerfile