skip to Main Content

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

Answers


  1. The syntax for the command is

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

    So it should be

    docker run ... --rm ... dockeragent:latest SOMESTUFF 
    
    Login or Signup to reply.
  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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search