user3751385
user3751385

Reputation: 4229

How to avoid typing the container id when using docker commit?

Creating a new docker image from a container is done with the following syntax:

    $ docker commit -m "commit message" -a "author" \ 
      #containerid user/imagename:tag

I know you can get the last container id from:

    $ docker ps -l

But that gives me verbose output. How can I regex the container id or input a command to extract just the last container id so that I don't have to manually type it into my commit message?

Upvotes: 0

Views: 86

Answers (1)

user3751385
user3751385

Reputation: 4229

I found the answer and thought I'd post it in case someone else runs into the same issue:

$ sudo docker commit -m "commit message" -a "author" \ 
  $(sudo docker ps -lq) user/imagename:tag

You use docker ps -lq

Upvotes: 1

Related Questions