I would like to build a minio docker container for integration test purposes.
I would like to do the following in my Dockerfile.
- Create the minio container
- Create a test bucket
- Copy a small amount of test data into a test bucket
- Start the minio service
Test Data
./test-data/foo.txt
./test-data/bar.txt
FROM minio/minio
RUN mkdir -p /buckets/my-bucket
COPY test-data /buckets/my-bucket/test-data"
EXPOSE 9000 9001
CMD [ "minio", "server", "/buckets", "--address", ":9000", "--console-address", ":9001" ]
I know that I could run mc
in a separate container to populate my bucket, but that requires a little bit of orchestration.
Is there a way that I could accomplish these steps in a Dockerfile?
CodePudding user response:
A Dockerfile is just a collection of shell commands...so you can do pretty much anything you want. For example:
FROM docker.io/minio/minio:latest
COPY --from=docker.io/minio/mc:latest /usr/bin/mc /usr/bin/mc
RUN mkdir /buckets
RUN minio server /buckets & \
server_pid=$!; \
until mc alias set local http://localhost:9000 minioadmin minioadmin; do \
sleep 1; \
done; \
mc mb local/bucket1; \
echo this is file1 | mc pipe local/bucket1/file1; \
echo this is file2 | mc pipe local/bucket1/file2; \
kill $server_pid
CMD ["minio", "server", "/buckets", "--address", ":9000", "--console-address", ":9001"]
If we use the above Dockerfile to build an image named minio-demo
, and then start a container like this:
$ docker run --rm -p 127.0.0.1:9000:9000 -p 127.0.0.1:9001:9001 minio-demo
We see:
$ mc alias set demo http://localhost:9000 minioadmin minioadmin
$ mc ls demo
[2022-07-07 22:01:35 EDT] 0B bucket1/
$ mc ls demo/bucket1
[2022-07-07 22:01:35 EDT] 14B STANDARD file1
[2022-07-07 22:01:35 EDT] 14B STANDARD file2