Hi, can you give some hint on how to do that and what to take care of?
Hi!
You need to make Dockerfile
with all required components, like external scripts and use the docker:latest
as a base image to be able to connect the docker daemon and to do docker ps
or docker logs
from the docker container.
See https://hub.docker.com/_/docker
Example:
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock docker:latest ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0b95bf0b7796 docker:latest "dockerd-entrypoint.…" 1 second ago Up Less than a second 2375-2376/tcp magical_colden
P.S. docker ps
works also:
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock docker:latest docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1b4f524fbd2c docker:latest "dockerd-entrypoint.…" 2 seconds ago Up Less than a second 2375-2376/tcp happy_bardeen
Example of Dockerfile
:
FROM docker:latest as build
RUN git clone https://github.com/fieu/discord.sh.git
FROM docker:latest
COPY --from build discord.sh/discord.sh .
COPY storj-system-health.sh .
RUN apk add bash jq curl
ENTRYPOINT ["bash", "-c", "./storj-system-health.sh"]
Then you need to build the image
docker build . -t storj-system-health.sh:latest
and run it:
docker run -it --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ${PWD}/storj-system-health.credo:/storj-system-health.credo \
--mount type=bind,source=/mnt/node,destination=/mnt/node \
--mount type=bind,source=/mnt/node/logs,destination=/logs \
--name storj-system-health \
storj-system-health.sh:latest param1 param2 param3 ...
Please note, in your *.credo
file you need to provide the IP of the host, not localhost
, since the script would work in the container, it would have an own localhost, where the storagenode dashboard wouldn’t be available. It also mean, that nodes must be run without binding the dashboard port to 127.0.0.1
.
This is a disposable container and it works as a script, so it can be configured with cron as in your documentation.
However, in the initial request it should be a standalone daemon-like application, so you need either to add a wrapper script which would run the main script periodically with sleep or use cron inside the container as ENTRYPOINT/CMD (could be a cumbersome: How to run a cron job inside a docker container? - Stack Overflow). You would need to change ENTRYPOINT
to point to that wrapper script or cron instead of your main script.