How can I list all tags for a Docker image on a remote registry?
Update: sadly this solution will no longer work because Docker has deprecated the v1 API.
I got the answer from here . Thanks a lot! :)
Just one-line-script:(find all the tags of debian)
wget -q https://registry.hub.docker.com/v1/repositories/debian/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}'
UPDATE
Thanks for @degelf's advice.
Here is the shell script.
#!/bin/bash
if [ $# -lt 1 ]
then
cat << HELP
dockertags -- list all tags for a Docker image on a remote registry.
EXAMPLE:
- list all tags for ubuntu:
dockertags ubuntu
- list all php tags containing apache:
dockertags php apache
HELP
fi
image="$1"
tags=`wget -q https://registry.hub.docker.com/v1/repositories/${image}/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}'`
if [ -n "$2" ]
then
tags=` echo "${tags}" | grep "$2" `
fi
echo "${tags}"
You can just create a new file name, dockertags
, under /usr/local/bin (or add a PATH env to your .bashrc
/.zshrc
), and put that code in it.
Then add the executable permissions(chmod +x dockertags
).
Usage:
dockertags ubuntu
---> list all tags of ubuntu
dockertags php apache
---> list all php tags php containing 'apache'
How to get the image name of a docker container from inside the container
This type of information/metadata is not passed into the container by default. There are 2 reasons for this.
- if every metadata about the container was passed into the container, it could potentially pose a security risk when someone breaks into it
- container shouldn't need this kind of information anyway
The reason why you can get access to container's ID from within the container is simply because it is used as the container's hostname by default. If you would specify hostname when running the container with container run --hostname ...
, you wouldn't have access to the ID either.
I don't know why you need this information but the only way to get it when you are inside of the container is to first pass it to the container in one way or another. For example via an environment variable.
If you don't have access to this information from the outside of the container (which seems strange if you are able to use docker exec
), you will not get it from the running container.
How to see docker image contents
If the image contains a shell, you can run an interactive shell container using that image and explore whatever content that image has. If sh
is not available, the busybox ash
shell might be.
For instance:
docker run -it image_name sh
Or following for images with an entrypoint
docker run -it --entrypoint sh image_name
Or if you want to see how the image was built, meaning the steps in its Dockerfile
, you can:
docker image history --no-trunc image_name > image_history
The steps will be logged into the image_history
file.
Related Topics
How to Authenticate Username/Password Using Pam W/O Root Privileges
Syntax Error Near Unexpected Token 'Do' When Run with Sudo
Force Netcat to Send Messages Immediately (Without Buffering)
When Is Posix Thread Cancellation Not Immediate
Need Explanation on Pri Standard Format Specifier for Ps - Possible Bug in Documentation
Autoconf Check for Program and Fail If Not Found
Automatically Adjusting Process Priorities Under Linux
While Using Printf How to Escape Special Characters in Shell Script
How to Convince Z/Os Scp to Transfer Binary Files
How to Move Old File to Another Folder
Sdl Configuration in Eclipse Ide
Bash Redirect to /Dev/Stdout: Not a Directory
Linux - Modify File Modify/Access/Change Time
How to Add My Scheduler to Linux Kernel
What Does It Mean to Break User Space