Like any other software, Docker introduces users to a new range of terminology related to its services. Users need to get familiar with concepts such as Dockerfiles, images, containers, and other Docker-specific words.
Once you have mastered the vocabulary, the next step is to get used to using Docker commands. A list of all the commands and options is quite extensive and would take time to learn them all by heart.
What is Docker?
Docker is a popular virtualization tool that replicates a specific operating environment on top of a host OS. It is used by development teams to ensure consistency across different machines. It is a software that offers a set of platform-as-a-service products for developing and deploying applications by packaging software in containers.
What is Container?
A container uses an image of a preconfigured operating system optimized for a specific task. When a Docker image is launched, it exists in a container. For example, multiple containers may run the same image at the same time on a single host operating system.
Containers are designed to provide a self-sufficient environment, with all the libraries and configurations needed for the software to execute.
Containers are lightweight, portable, virtual environments that developers can share without risking inconsistencies in development. Due to these incredibly useful features, now organizations are switching from using virtual machines to Docker containers.
What is Containerization?
Containerization is defined as a form of operating system virtualization, through which applications are run in isolated user spaces called containers, all using the same shared operating system (OS).
No matter if you are new to Docker or already have some experience with containerization, it is always good to have a reference point for all the common Docker commands.
During development, they can grow unorganized with old, outdated, and unused components. Where require maintenance to manage, free resources and reclaim for different uses.
Let’s learn few commands which will be useful to work and maintain docker containers, images and other resources.
We will see few options to list, start, and stop, Docker containers.
The basic format for using docker is:
docker command [options]
To list all running Docker containers
To list all containers, both running and stopped
docker ps –a
Since I am having only one container running at moment, so to show difference from previous command I stopped the container.
Now I have started the container and issued same commands as above.
Docker ps lists only running containers
Docker ps -a lists running and stopped containers.
To list containers by their ID
docker ps –q
My Container was running
Remember from above Docker ps -a lists running and stopped containers. My Container is stopped
To list the total file size of each container
docker ps –s
You can check supported options using:
Use the docker stop command to stop a container:
docker stop [option] container_id
By default, you get a 10 second grace period. The stop command instructs the container to stop services after that period. Use the –time option to define a different grace period expressed in seconds:
docker stop –time=20 container_id
To Start Container
docker start container_id
To immediately kill a docker container without waiting for the grace period to end use:
docker kill [option] container_id
To stop all running containers, enter the following:
docker stop $(docker ps –a –q)
The same command could be used with kill. This would stop all containers without giving them a chance to exit.
Don’t forget to check next post where we will discuss about commands helpful in doing maintenance of containers.