Hsn723 / postfix_exporter

A Prometheus exporter for Postfix.
Apache License 2.0
4 stars 0 forks source link

How do I run container with flags? #61

Open jamesgreen-moj opened 2 months ago

jamesgreen-moj commented 2 months ago

This is my current configuration: https://github.com/ministryofjustice/staff-infrastructure-smtp-relay-server/commit/e568fe551757f98af05f6b34820a1782be80e8e9

I am trying to pass in flags such as

--postfix.logfile_path=/var/log/mail/postfix

However due to the base container being "scratch", I cannot seem to pass in flags anymore.

for example: ➜ staff-infrastructure-smtp-relay-server git:(nd-310) ✗ docker run --entrypoint "/postfix_exporter" docker_smtp_relay_monitoring:latest
2024/04/29 13:12:42 Reading log events from /var/log/mail.log 2024/04/29 13:12:42 Error opening log source: open /var/log/mail.log: no such file or directory

➜ staff-infrastructure-smtp-relay-server git:(nd-310) ✗ docker run --entrypoint "/postfix_exporter --postfix.logfile_path=test.log" docker_smtp_relay_monitoring:latest

docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/postfix_exporter --postfix.logfile_path=test.log": stat /postfix_exporter --postfix.logfile_path=test.log: no such file or directory: unknown.

Can you provide an example with how this is being used?

Hsn723 commented 1 month ago

In your example, you are overriding the entrypoint, however entrypoint only takes a single entrypoint without arguments. With docker, anything after the image is passed to the entrypoint, so you can pass flags to the container by specifying them after the container image, like so:

docker run ghcr.io/hsn723/postfix_exporter:0.6.0 --no-postfix.logfile_must_exist

In the above example the entrypoint will be called with --no-postfix.logfile_must_exist. You can refer to the docker run documentation for a more detailed explanation on overriding image defaults.

If you want to rewrite the entrypoint in a Dockerfile like in your sample configuration, you should use CMD (and ARG whenever necessary) instead of ENTRYPOINT. You can refer to the Dockerfile documentation for a more detailed explanation on how to use the CMD instruction and how it differs from ENTRYPOINT.