Docker has revolutionized the way we build, ship, and run applications by leveraging containerization technology. With Docker, you can package your applications and all their dependencies into a single container, ensuring consistency across different environments.
To help you get started with Docker, here is a compilation of some basic commands that will empower you to work with containers efficiently.
1. `docker info`
The `docker info` command provides essential information about your Docker installation. It gives you details about the number of containers, images, networks, and other relevant system information.
docker info
2. `docker` command format
The `docker` command is the core of the Docker CLI (Command Line Interface). It allows you to interact with Docker and manage containers, images, networks, volumes, and more. The older format with double dashes `–docker` is still functional, but the more common usage is just `docker`.
docker [command]
3. `docker container run`
The `docker container run` command is used to create and start a new container from a specified image. By default, it runs the container in the foreground. To run the container in the background, you can use the `–detach` or `-d` option. Here’s an example of running an Nginx web server in the background and publishing port 80 on the host to port 80 in the container:
docker container run --publish 80:80 --detach nginx
4. `docker container ls`
The `docker container ls` command lists all the running containers. By default, it only shows the running containers. To see all containers, including the stopped ones, you can use the `-a` or `–all` option.
docker container ls
docker container ls -a
5. `docker container stop`
The `docker container stop` command is used to gracefully stop a running container. You need to provide the container ID or container name as an argument to this command.
docker container stop {container_id}
6. `docker container logs`
The `docker container logs` command allows you to view the logs generated by a specific container. You need to specify the container name or container ID as an argument to this command.
docker container logs {containerName}
7. `docker container top`
The `docker container top` command displays the running processes within a container. It provides valuable insights into the processes running in a specific container.
docker container top {containerName}
8. `docker container rm`
The `docker container rm` command is used to remove one or more stopped containers. However, if a container is running, the command will fail. To forcibly remove a running container, you can use the `-f` or `–force` option.
docker container rm {container_id}
docker container rm -f {container_id}
9. `docker container inspect`
The `docker container inspect` command provides detailed information about a container, including its configuration, network settings, and more.
docker container inspect {container_id}
10. `docker container stats`
The `docker container stats` command displays live performance statistics of a running container, such as CPU and memory usage.
docker container stats
11. `docker container update`
The `docker container update` command allows you to modify the configuration of one or more running containers. This is useful for changing container settings without stopping and recreating them.
docker container update --help
These basic Docker commands are just the tip of the iceberg. Docker provides a rich set of features and functionalities that can significantly simplify the development and deployment process of your applications. With time and practice, you will become more comfortable with Docker and unleash its full potential in your projects.
Happy containerizing!
You may also like:- Top 40 Useful Linux Command Snippets
- Essential Commands For Process Management in Kali Linux
- A Comprehensive Guide to File System Commands in Linux
- Essential File Compression Commands in Linux
- Secure Shell (SSH) Protocol – A Comprehensive Guide
- Monitoring Active Connections in Kali Linux Using Netstat
- Manage Time and Date in Linux with timedatectl
- How to Add a User to Sudoers on Ubuntu
- 25 Popular Linux IP Command Examples
- Top 11 Nmap Commands for Remote Host Scanning