Home > Software design >  Docker run not recognizing --rm
Docker run not recognizing --rm

Time:07-22

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

CodePudding user response:

The syntax for the command is

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

So it should be

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

CodePudding user response:

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

  • Related