Posts

Showing posts with the label dockerfile

ENTRYPOINT and CMD with build arguments

ENTRYPOINT and CMD with build arguments This doesn't work: FROM alpine:3.7 # build argument with default value ARG PING_HOST=localhost # environment variable with same value ENV PING_HOST=${PING_HOST} # act as executable ENTRYPOINT ["/bin/ping"] # default command CMD ["${PING_HOST}"] It should be possible to build an image with build-arg and to start a container with an environment variable to override cmd as well. docker build -t ping-image . docker run -it --rm ping-image Error: ping: bad address '${PING_HOST}' UPDATE: FROM alpine:3.7 # build argument with default value ARG PING_HOST=localhost # environment variable with same value ENV PING_HOST ${PING_HOST} COPY ./entrypoint.sh /usr/local/bin/ # act as executable ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] # default command CMD $PING_HOST entrypoint.sh #!/bin/sh /bin/ping $PING_HOST This works because the entrypoint.sh enables variable substitution as expected. Wh...