Reputation: 508
《The Docker Book v17.12.0-ce》 Page 223
Listing 6.19: Our war fle fetcher
FROM ubuntu:16.04
MAINTAINER James Turnbull
ENV REFRESHED_AT 2016-06-01
RUN apt-get -yqq update
RUN apt-get -yqq install wget
VOLUME [ "/var/lib/tomcat7/webapps/" ]
WORKDIR /var/lib/tomcat7/webapps/
ENTRYPOINT [ "wget" ]
CMD [ "-?" ]This incredibly simple image does one thing: it wgets whatever fle from a URL that is specifed when a container is run from it and stores the fle in the /var/lib /tomcat7/webapps/ directory. This directory is also a volume and the working directory for any containers. We’re going to share this volume with our Tomcat server and run its contents. Finally, the ENTRYPOINT and CMD instructions allow our container to run when no URL is specifed; they do so by returning the wget help output when the container is run without a URL.
Can anyboy tell me what's the meaning of "CMD [ "-?" ]"
I know the concept of ENTRYPOINT and CMD, what I don't understand is the meaning of "-?" in "wget -?"
Upvotes: 0
Views: 1101
Reputation: 508
I figure it out, The author made a clerical error. The arguments in CMD should be "-h". Because in the later he said " Finally, the ENTRYPOINT and CMD instructions allow our container to run when no URL is specifed; they do so by returning the wget help output when the container is run without a URL."
Upvotes: 0
Reputation: 159742
When you run a Docker container, it constructs a command line by simply concatenating the "entrypoint" and "command". Those come from different places in the docker run
command line; but if you don't provide a --entrypoint
option then the ENTRYPOINT
in the Dockerfile is used, and if you don't provide any additional command-line arguments after the image name then the CMD
is appended.
So, a couple of invocations:
# Does "wget -?"
docker run --rm thisimage
# Does "wget -O- http://stackoverflow.com": dumps the SO home page
docker run --rm thisimage -O- http://stackoverflow.com
# What you need to do to get an interactive shell
docker run --rm -it --entrypoint /bin/sh thisimage
Upvotes: 1