Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Docker container ID alone

I have only one docker instance running. My actual task to write shell script around this container.

However the first step is to get the container ID via a shell command.

Is there a shell command to do it?

like image 707
suryakrupa Avatar asked Aug 28 '15 00:08

suryakrupa


People also ask

How do I find the container ID of a container?

Find the running container's ID by using the docker ps command. Find the PID number of the first process in the running container by running the docker inspect command. Enter the running container by using the nsenter command.

Is docker container ID unique?

When you create a Docker container, it is assigned a universally unique identifier (UUID). These are essential to avoid naming conflicts and promote automation without human intervention.

Is container ID and image ID same?

Like IMAGE ID, CONTAINER ID is the true identifier for the container. It has the same form, but it identifies a different kind of object. docker ps only outputs running containers. You can view all containers (running or stopped) with docker ps -a.


1 Answers

you can do either

docker ps -q

or also, as the only running container is also the last one

docker ps -lq

like image 106
user2915097 Avatar answered Oct 05 '22 09:10

user2915097