According to its official website, Docker is a containerization platform. It enables programmers to package applications into capsules, which have been standardized executable portions that integrate program code only with OS packages and prerequisites needed to execute on nearly any architecture.
The Docker architecture has provided a terminal service that allows everyone to run a variety of instructions to get information from vessels or containers. Dockers have different instructions that are used for various purposes. One of the most-known commands is the “docker ps” command that is used to get information regarding the docker containers currently available in your docker framework. So, we have decided to use this article to illustrate how the “docker ps” instruction works and how we can see the overall full instruction at our Linux shell using the “—no-trunc” option in it.
To start, we will be logging in from our system and using the “Ctrl+Alt+T” for the terminal console to start quickly. You have to delete all the already installed old packages docker along with other related packages from Ubuntu 20.04 system. So, the apt-get instruction has been utilized so far followed by the keyword “remove” and the names of packages to be removed. Add your current account password and press the Enter key to continue it.
Within a while, the whole docker and its other library packages will be deleted magnificently.
You can use either the “apt-get” package or the “snap” package to install it. Choose the “apt” package to install it as we have used it in below “install” instructions along with the docker package “docker.io”.
Tap “y” on asked: “Do you want to continue” to complete the installation.
After completing the removal and installation, you must update Ubuntu 20.04 using the apt-get update instruction as shown beneath. Add your password and continue.
The installed version of docker can be found with the help of an instruction executed in the images below. The current version of docker installed is “20.10.12”.
Now, it’s time to look at how the “docker ps” instruction works at our end within the Ubuntu 20.04 system. So, we must use the shown-below “docker ps” instruction to get data regarding the running container of our docker platform. It turns out that there is not a single container in our docker platform. So, we need to create one.
But before that, we have utilized the same “docker ps” instruction with the “—no-trunc” option to see how it works. As there are no containers, so there is no output to be seen.
Let’s look at the docker images that are available for Ubuntu 20.04 system. Therefore, we have been making use of the “docker images” instruction to list all the images. There are a total of 3 images available for our use. Let’s use them to make containers.
The images must be pulled before being used for making containers. So, we have used the “docker pull” instruction to pull the busybox and ubuntu images in our docker platform. Both images have been successfully pulled and are ready for our use.
You need to run the pulled-out images at your shell terminal to make containers after that. So, try the “docker run” instruction along with the name of an image as displayed below. We have been running all the available images here.
$ sudo docker run busybox
$ sudo docker run hello-world
After pulling and running the images, it’s high time to check out the container information using the “docker ps -a” query. It shows that three containers have been made successfully.
Now, we will be looking at the output of the “docker ps” instruction along with the option “—no-trunc”. As there is no container running currently, hence no output.
We need to run a container with a new name using the “run” instruction of docker. We have been using the “—name” option to retitle the container “busy box” to “New”. Also, the “-it” option will open the interactive console in our shell. The container “New” started running as its terminal was launched. This console area can be used to get information regarding the running container via the use of certain docker instructions.
So, for an instance, we have executed the list “ls” query to list out all the directories from the container “New”. All the directories are listed on our output screen. Right now, the container is running successfully.
Now, when we run the “docker ps” instruction at the shell, the output shows us the currently running container “New” and its related information (i.e. container id, name, command, created time, status, and ports.) This information is a little reserved as it doesn’t show the filling output. So, we have tried this instruction again with the “—no-trunc” option. This time, it is showing us the full output of the “docker ps” instruction i.e. full container ID and other information.
$ sudo docker ps - -no-trunc
Just like that, the “—no-trunc” option can also be utilized with the “docker ps –a” instruction to display the extra information regarding containers.
This was all about the working of docker containers in Ubuntu 20.04. We have discussed the ways to pull and run the images of a docker at our end and the ways to create a new running container using the “run” instruction. The “docker ps” instruction has been used at several steps to display its currently running containers and the “—no-trunc” option is used to display its full output.