What is the command to get the docker container id from the container name?
相关问题
- Docker task in Azure devops won't accept "$(pw
- Unable to run mariadb when mount volume
- Unspecified error (0x80004005) while running a Doc
- What would prevent code running in a Docker contai
- How to reload apache in php-apache docker containe
You can try this:
This approach is OS independent.
In Linux:
Or in OS X:
where
containername
is your container nameexplanation:
-q
for quiet. output only the ID-a
for all. works even if your container is not running-f
for filter.If you want to get complete ContainerId based on Container name then use following command
The simplest way I can think of is to parse the output of
docker ps
Let's run the latest ubuntu image interactively and connect to it
If you run
docker ps
in another terminal you can see something likeUnfortunately, parsing this format isn't easy since they uses spaces to manually align stuff
Here is a script that converts the output to JSON.
https://gist.github.com/mminer/a08566f13ef687c17b39
Actually, the output is a bit more convenient to work with than that. Every field is 20 characters wide.
[['CONTAINER ID',0],['IMAGE',20],['COMMAND',40],['CREATED',60],['STATUS',80],['PORTS',100],['NAMES',120]]
Get container Ids of running containers ::
Get container Ids of all containers ::