Search code examples
dockerdocker-composeminio

How to prevent Minio MC to exit in docker compose


I use Minio and Minio/MC in my docker-compose as follows:

version: '3'

services:
  minio:
    image: minio/minio
    command: server --address 0.0.0.0:9000 --console-address 0.0.0.0:9001 /data
    volumes:
      - minio-data:/data
    expose:
      - 9000
    ports:
      - "9001:9001"
    environment:
      MINIO_ROOT_USER: minio
      MINIO_ROOT_PASSWORD: minio123

  ready_minio:
    image: minio/mc
    env_file:
      - ./envs/local.env
    entrypoint: >
      /bin/sh -c "
          until (/usr/bin/mc config host add myminio http://minio:9000 minio minio123) do echo '...waiting...' &&
      sleep 1;
      done;
      /usr/bin/mc alias set myminio http://minio:9000 minio minio123;
      /usr/bin/mc admin user add myminio/ $${MINIO_ACCESS_KEY} $${MINIO_SECRET_KEY};
      /usr/bin/mc admin policy set myminio/ readwrite user=$${MINIO_ACCESS_KEY};
      /usr/bin/mc mb myminio/$${MINIO_MEDIA_FILES_BUCKET};
      /usr/bin/mc policy set public myminio/$${MINIO_MEDIA_FILES_BUCKET};
      exit 0;
      "

    depends_on:
      - minio

volumes:
  minio-data:

After all lines of entrypoint are executed, ready_minio container will be exited.
I want minio/mc to remain running after the execution of entrypoint commands is finished so that I can run other commands via docker exec -it ready_minio /bin/sh or something like that. How can I do that?

Already tried ways: I removed exit 0; from the last line of the entrypoint and this has not solved the problem.


Solution

  • If you want the container to continue running, then you need to provide a command that will not exit. A common option for "do nothing, forever" is the sleep inf command:

    ready_minio:
      image: minio/mc
      env_file:
        - ./envs/local.env
      entrypoint: >
        /bin/sh -c "
            until (/usr/bin/mc config host add myminio http://minio:9000 minio minio123) do echo '...waiting...' &&
        sleep 1;
        done;
        /usr/bin/mc alias set myminio http://minio:9000 minio minio123;
        /usr/bin/mc admin user add myminio/ $${MINIO_ACCESS_KEY} $${MINIO_SECRET_KEY};
        /usr/bin/mc admin policy set myminio/ readwrite user=$${MINIO_ACCESS_KEY};
        /usr/bin/mc mb myminio/$${MINIO_MEDIA_FILES_BUCKET};
        /usr/bin/mc policy set public myminio/$${MINIO_MEDIA_FILES_BUCKET};
        exec sleep inf;
        "