Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the names of containers in Docker

Tags:

docker

I named my containers in Docker, but now I forgot the names...

How can I list all of the used names?

docker -ps just gives me the running containers and docker images gives me all the images but no names.

I just want a list where I can see how I named the different containers when I created them.

like image 629
Maximilian Kindshofer Avatar asked Dec 13 '16 13:12

Maximilian Kindshofer


People also ask

How to list containers in Docker?

How to List Containers in Docker? 1 We have to use the Docker CLI tool to execute the command to list the containers. 2 We have two Docker commands that list the containers. 3 The first one is ‘docker container ls’ and the second one is ‘docker ps’. More items...

How to get the user name of a docker container?

Use docker inspect + container id and grep user or name then you can get the Container User Name and login into the container. Thanks for contributing an answer to Stack Overflow!

What does the command command do in Docker?

Command - The default command that is executed while starting a container Created - Relative time when the container was created Status - The state of the container (will be explained later) Ports - Published ports of the container

How to launch multi-container with docker-compose?

Docker-compose can easily launch multi-container with the config file (default: docker-compose.yml ). For example, we have the following files. It is noticeable that the container’s name follow this %container_name_%s The prefix index of the container is added after the container’s name _%s.


2 Answers

As mentioned by @nwinkler, you use docker ps -a to list all of your containers even stopped ones.

Now, you can also use Format in combination to docker ps -a as a convenient way to print only part of the information that is relevant to you.

For example you can list your container IDs with their associated names with:

$ docker ps -a --format "{{.ID}}: {{.Name}}"
caee09882462: peaceful_saha

You can also use the regular table format with the column titles:

$ docker ps -a --format "table {{.ID}}\t{{.Names}}"

CONTAINER ID        NAMES
caee09882462        peaceful_saha

If you only want a list of all the used names:

$ docker ps -a --format "{{.Names}}"
peaceful_saha
like image 171
abronan Avatar answered Oct 28 '22 15:10

abronan


You can run docker ps -a to show all running and stopped containers.

The container ID will be in the first column of the output, and the name will be in the last column.

Example:

$ docker ps -a
CONTAINER ID  IMAGE                    COMMAND                  CREATED       STATUS                    PORTS                                                     NAMES
6b74154d7133  wnameless/oracle-xe-11g  "/bin/sh -c '/usr/sbi"   9 months ago  Exited (0) 13 days ago    8080/tcp, 0.0.0.0:49160->22/tcp, 0.0.0.0:49161->1521/tcp  oracle_xe
like image 32
nwinkler Avatar answered Oct 28 '22 14:10

nwinkler