docker – It is not possible to pass the argument correctly when running into a container

Question:

I'm taking the Computing Management course. Question on assignment:

You need to create a Dockerfile, which will describe how to create an image with the following properties:

  • When starting a container from this image with no arguments, it should output the string "Hello World!" and shut down
  • When starting a container with an <arg> argument, the string "Hello <arg>!" Should be output, after which the container should exit.

An example of how the solution should work:

docker build -t test.

docker run –rm test

> Hello World!

docker run –rm test Universe

> Hello Universe!

My decision:

FROM ubuntu:14.04

LABEL maintainer="Egor Urvanov"

ENTRYPOINT ["echo", "Hello"]
CMD ["world!"]

The problem is that when I run a container from an image with an argument, I cannot display

> Hello Universe!

How can this error be corrected.

Here you can find the complete assignment.

Answer:

The arguments passed can be retrieved via $.

Your working Dockerfile:

FROM ubuntu:14.04
LABEL maintainer="Egor Urvanov"
ENTRYPOINT ["echo", "Hello"]
CMD $1
Scroll to Top