Common commands in Docker
Docker is a computer program that performs OS-level virtualization, also known as "containerization".
The Docker commands the user should know
- 1. Export nginx server container with a single command
- 2. Run a container in the background
- 3. List all running containers
- 4. Stop a container
- 5. Run the new container with the specified name
- 6. View container log
- 7. See the running processes in a container
- 8. List all commands with the help command
- 9. List all containers
- 10. Delete container by container ID
- 11. Force removal of running containers
- 12. Delete all containers with wildcards instead
1. Export nginx server container with a single command
docker container run --publish 80:80 nginx
Executing the above command will work as follows:
- Download the 'nginx' image from the Docker hub.
- Start a new container from that image.
- Open port 80 on the server IP.
- Routing traffic to IP containers, port 80.
2. Run a container in the background
docker container run --publish 80:80 --detach nginx
This command runs on nginx server in the background. Option to detach Docker running container in the background.
3. List all running containers
docker container ls
The above command lists all containers in Docker and their status.
4. Stop a container
docker container stop {containerID}
ContainerID can be found using the ls command listing the list of all containers. The container ID may be several digits, as long as it is unique.
5. Run the new container with the specified name
docker container run --publish 80:80 --detach --name linuxhost nginx
A new container with nginx web server image starts with the name linuxhost.
6. View container log
docker container logs {containerName}
The above command displays the log for the specified container. The name of the container can be obtained using the ls command listing the list of all containers.
7. See the running processes in a container
docker container top {containerName}
This command lists all running processes in the container. The name of the container can be obtained using the ls command listing the list of all containers.
8. List all commands with the help command
docker container --help
This command lists all user commands that can be performed on a container.
9. List all containers
docker container ls -a
This command lists all containers with any status in Docker.
10. Delete container by container ID
docker container rm {containerID1} {containerID2} .
This command will delete all non-running ID containers specified by spaces.
11. Force removal of running containers
docker container rm -f {containerID}
The -f option allows the rm command to remove a container running in Docker.
12. Delete all containers with wildcards instead
docker stop $(docker ps -a -q) docker rm $ (docker ps -a -q)
This command stops all containers first and then removes all of them. On Windows 10, use Powershell instead of the Command Prompt and the above commands will work.
Good luck!
See more:
- 5 tips to learn Docker effectively for beginners
- How to safely check desktop applications with Docker
- 5 useful tips to learn Docker
You should read it
- How to run Docker on Raspberry Pi
- How to use Docker Container
- 10 Best Docker Alternatives 2023
- Docker best practices you need to know
- How to disable Containers feature on Firefox browser?
- How to Containerize a Nest.js Application Using Docker and Docker Compose
- Lesson 2: Learn about Containers in Bootstrap 5
- 6 reasons to use Docker virtualization software
May be interested
- Containerize Go App with Dockerlearn how to use docker to efficiently package and deploy go applications, making them flexible and manageable. here are detailed instructions.
- What is Docker Compose? Summary of knowledge about Docker composedocker compose is a tool used to define and run docker programs using multiple containers (multi-containers).
- How to install Docker in Linuxdocker is a containerized utility that has become very popular, simplifying such tasks. moreover, when there is a problem with the operating system, instead of installing and reconfiguring the application, users only need to reinstall the operating system, copy the container again.
- 5 tips to learn Docker effectively for beginnersto keep up with this new technology trend, many people are starting to learn docker. for beginners familiar with docker, please refer to the article below to achieve high results.
- How to containerize a Rust app with Dockercontainerize rust apps with docker to simplify deployment and ensure consistency across different environments.
- 10 Best Docker Alternatives 2023some developers have complained about the challenges associated with using docker containers during application development.
- How to Run GUI-Based Applications in Dockerdocker is typically used for server-side and command-line applications. however, with the right setup, you can also run gui-based applications inside containers.
- Docker and .NET APIs: Simplifying Deployment and Scalingthis article explores the benefits of using docker with .net applications and provides step-by-step instructions for getting started.
- How to create an effective Docker image for a Python projectdocker images are powerful tools for distributing python projects, but it's important to keep them as clean as possible.
- Common Run commands for Windows you should knowcommon run commands for windows you should know. summary of run commands useful in windows xp, windows 7, windows 8 and windows 8.1. with these run commands you can work faster, use that more professional computer.