Docker Services shutsdown once its up . How to avoid it

Hello ,

I have created Docker containers using Docker-compose and ran them using docker stack deploy commands

version: "3"
services:
  web:
    # replace username/repo:tag with your name and image details
    image: client:latest
    command: "/app/startserver.sh ${hostname}"
    deploy:
      replicas: 3
      mode: replicated
    ports:
      - "8999:8999"
    networks:
      - webnet
  service:
    # replace username/repo:tag with your name and image details
    image: service:latest
    deploy:
      replicas: 1
      mode: replicated
    ports:
      - "38080:8080"
networks:
  webnet:

Docker stack deploy -c docker-compose.yml sampleservice would start the services with expected replicas . Now Once the containers are up it shutsdown immediately and new containers are created and this continues throughout.

Even the startserver.sh file has sleep infinity placed at the end and still it goes down and new ones are created . I am unable to find the reason for the termination . I tried docker stack ps sampleservice and I dont see any details in the error column .

Please help to resolve.

I just checked . If the replica service for web is 2 . Then it works fine . When I increase it it kills once the containers are up . :frowning: Any idea folks about this behaviour.

can you use

docker logs container_id

for one of the containers that ended to see if they will provide an error?

I did . I dont see anything odd. :frowning: . As soon as the container is up , new containers are spinned up and old ones are removed . happening when I increase the replica to 3 fow web

did you look at the logs AFTER the container ends?

Damn :cry:, In the client I am downloading a file from artifact and then start the same . Seems all of 3 containers have stopped in the miidle of the download process . :open_mouth:
i think it should be something related to timeout . As with 2 containers its able to process when I increase the timeout lapses … What you think !!

sorry, no idea… what is the source of the download? “a file from artifact”???

From Jfrog-artifactory . It works fine with 2 . … strange …

ok, i have never seen a problem with artifactory like this…

i might try this manually (a script to download the artifacts) and run it multiple times concurrently to see if you can replicate the problem without containers and find the cause.

I am gonna try to add this now

deploy:
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
        window: 120s

I think the window is the key to ask the engine to wait before restarting

well, that is a workaround… but not a fix… it will come back to bite you again sometime…

1 Like

I got the error message Exited (137) .

CONTAINER           CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
9d521c930d67        3.34%               206.2MiB / 1.795GiB   11.22%              10.1kB / 3.99kB     678MB / 470MB       50

I think I caught the issue . Its with the memory . My service container takes 38% and all the 3 web takes 44.8% . So this lead to crash . Increase in my memory or maintaing it to 2 should work :slight_smile: Thanks a lot for your response .

great feedback… thanks…