Search code examples
containersdocker-swarm

Unable to create docker service


I'm learning docker swarm and I am trying to create the docker service after initializing the swarm . I have created 3 EC2 instances and initialised a swarm with 1 manager and 2 worker nodes. I issue the following command on the manager

docker service create --replicas 3 alpine

The prompt never returns and I can only see that the status changes frequently - ready, starting, running, pending etc.

enter image description here

I recreated the EC2 instances and tried again but the same thing happens. Am I missing something here?


Solution

  • Quite common to miss this. Your only issue is that the alpine containers exit immediately as there are no running processes inside it. You need to keep it alive, something like this will help

    docker service create --replicas 3 -dt alpine
    

    -d: detach, make the terminal available again
    -t: run the terminal process inside the container

    Your service has been created. You may check the same using these commands below. Notice that you will see the 'Shutdown' status for the containers as they have already exited.

    Docker service ls
    Docker service ps service-name (from above command)