3

I am using docker-compose to start a minio service and a minio/mc service (createbuckets) to create a default bucket. For minio failure detection, I am using the exit code of the mc command that adds a host to the config for failure detection. The docker-compose file is listed below.

I cannot seem to be able to get the createbuckets service to return an exit code of any value other than 0 when the mc add host command fails in the entrypoint command string. Can anyone spot why this error is occurring? I am running this in a MacOS environment. I have found that the expected behaviour almost works in a Linux OS Environment. Please refer to added comment below.

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-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 minio.

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
      "

Solved using netcat for failure detection of minio

Based on https://stackoverflow.com/a/48215226/8325270 and https://8thlight.com/blog/dariusz-pasciak/2016/10/17/docker-compose-wait-for-dependencies.html I discarded the use of a command's exit status as a failure detection method for connection to minio. This was done in favour of the netcat utility. The docker compose file is listed below. Furthermore, I removed the healthcheck section in the minio service since conditional depends_on was removed in v3 of the docker-compose file specification.

version: "3.4"
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


createbuckets:
  image: minio/mc
  links:
    - minio
  restart: on-failure
  entrypoint: >
    /bin/sh -c "
      echo Waiting for minio service to start...;
      while ! nc -z minio 9000;
      do
        sleep 1;
      done;
      echo Connected!;
      mc config host add myminio http://minio:9000 accesskey secretkey;
      /usr/bin/mc rm --recursive --force myminio/uploads;
      /usr/bin/mc mb myminio/uploads;
      /usr/bin/mc policy download myminio/uploads;
      /usr/bin/mc policy upload myminio/uploads;
      exit 0;
    "
dcs3spp
  • 493
  • 1
  • 9
  • 23
  • Tried the script on a Linux OS environment and works if issue the command docker-compose -f myfile.yaml up minio createbuckets Exits with status 1 and retries in the event that fails to connect to minio service. If I issue docker-compose -f myfile.yaml up then exits with status code 0 and no retry. Why? Editing original question to update with detail that using a MacOS environment. – dcs3spp Oct 10 '18 at 17:07

0 Answers0