Working with alpine in docker and trying to start named but it only exits (with zero output)
This works
CMD /usr/sbin/named -f -c /etc/bind/named.conf
and is then represented in the docker image as
"Cmd": [
"/bin/sh",
"-c",
"/usr/sbin/named -f -c /etc/bind/named.conf"
However this does NOT work.
CMD ["/usr/sbin/named", "-f", "-c /etc/bind/named.conf"]
Here's the full Dockerfile, I also use it for CI Test
FROM alpine
RUN apk --no-cache add bind bind-tools bash
CMD /usr/sbin/named -f -c /etc/bind/named.conf
You're confusing arguments for the command.
With
CMD ["/usr/sbin/named", "-f", "-c /etc/bind/named.conf"]
, the program sees it as:However using a shell, because the shell does parameter splitting for you, the actual command is:
So you probably should write the Dockerfile like this:
The CMD command has three variants:
["executable", "param1", "param2"]
["param1", "param2"]
executable param1 param2
The second one is only valid if
ENTRYPOINT
is specified in the image. The dirrerence between the first and third one is that the exec form does not run shell and shell form does.In other words
CMD /usr/sbin/named -f -c /etc/bind/named.conf
on Alpine actually runs/bin/sh -c "/usr/sbin/named -f -c /etc/bind/named.conf"
and is therefore equivalent toCMD ["/bin/sh", "-c", "/usr/sbin/named -f -c /etc/bind/named.conf"]
, which why both work.As for
CMD ["/usr/sbin/named", "-f", "-c /etc/bind/named.conf"]
it passes TWO arguments tonamed
:-f
and-c /etc/bind/named.conf
, when clearly you want to pass THREE arguments:-f
,-c
and/etc/bind/named.conf
.You should try
CMD ["/usr/sbin/named", "-f", "-c", "/etc/bind/named.conf"]
. It will probably work as I do not think thatnamed
requires the shell.See also Dockerfile reference for CMD