Skip to content
Advertisement

Bash get docker image ID automatically

I’m trying to run a few docker commands in my linux machine:

JavaScript

But I would like to make a runme.sh and execute all in one run. The problem is that ImageID bf46cff9b182 is dynamiccally changing everytime. So I need to somehow pipe it from the output of the load command, which is in fact possible.

The output of load is like this:

JavaScript

On Linux it is shown as this:

JavaScript

And the 12 characters after sha256 would be bf46cff9b182, which would me my Image ID inserted in command #2 above.

How can I write a bash command to do this automatically?

Advertisement

Answer

Here’s a simple sed script to extract the sha256.

JavaScript

You can now capture this into a variable, or pipe it onward with xargs:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement