Docker-compose entrypoint /bin/sh -c exit code always 0 when exit with shell variable error value

Hi,

I am using docker-compose to start a minio service and minio/mc container to create a default bucket. I cannot seem to be able to get the createbuckets service to return an exit code of any value other than 0 when a command in the entrypoint command string fails…anyone spot why this error is occurring?

For info…the entrypoint checks the success of the command to add minio as a host to the mc command client config. I have specified a restart policy of on on-failure so that I can signal a failure exit code of 1 if this fails, thus restarting the createbuckets service until it can connect to the minio service.

I am running docker-compose in MacOS. I have tried the script in a Linux OS environment and it works if I issue the command docker-compose -f myfile.yaml up minio createbuckets. In this case an exit with status 1 occurs in the event that createbuckets service fails to connect to the minio service. If I issue docker-compose -f myfile.yaml up in a Linux OS environment then the createbuckets service exits with status code 0 and no retry occurs. Why?

Any ideas?

Kind regards

dcs3spp

version: "3"
services:
  minio:
    image: minio/minio
    ports:
      - "9000:9000"
    volumes:
      - ./docker/minio-data:/export
      - ./docker/minio-config:/root/.minio
    environment:
      - "MINIO_ACCESS_KEY=accesskey"
      - "MINIO_SECRET_KEY=secretkey"
    command: server /export
    healthcheck:
        test: ["CMD", "curl", "-f", "http://localhost:9000"]
        interval: 30s
        timeout: 10s
        retries: 5


  createbuckets:
    image: minio/mc
    depends_on:
      - minio
    restart: on-failure
    entrypoint: >
      /bin/sh -c "
        mc config host add myminio http://minio:9000 accesskey secretkey;
        success=$$?;
        if [ $$success -ne 0 ]; then \
          echo error encountered;
        else \
          /usr/bin/mc rm -r --force myminio/uploads;
          /usr/bin/mc mb myminio/uploads;
          /usr/bin/mc policy download myminio/uploads; \
        fi
        echo the variable value is $$success;
        if [ $$success -ne 0 ]; then exit 1; else exit 0; fi
      "

Cheers, thanks joffrey. Solved it as detailed at stack overflow