-1

I am trying to set up a docker container that automatically deletes itself when done. I see there is a command to do this built into docker with the --rm flag.

I have my image and can build a container and run a job from an azure agent in it. The only thing left to do is to have it clean up after itself.

Here is the command I use to run it:

docker run -e SOMESTUFF dockeragent:latest --once --rm

And this is the error I get:

docker : Unrecognized command-line input arguments: 'rm'. For usage refer to: .\config.cmd --help or ./config.sh --help
At line:1 char:1

Why can it not recognize the input rm? https://docs.docker.com/engine/reference/run/#clean-up---rm

2 Answers2

3

The syntax for the command is

$ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]

So it should be

docker run ... --rm ... dockeragent:latest SOMESTUFF 
Yury Tarabanko
  • 44,270
  • 9
  • 84
  • 98
2

All flags should come before the container name:

$ docker run --rm -e SOMESTUFF dockeragent:latest ...

everything that comes after the image name is passed as an argument to the entrypoint

Paolo
  • 21,270
  • 6
  • 38
  • 69