-
Get in touch
- Servers 99 611 Gateway Blvd ,
South San Francisco ,
CA 94080 United States - sales@servers99.com
- Whatsapp : +1 312 910 5075
- Support : +1 234 285 8020
- Skype Name : live:.cid.fceb43fa6d632b51
Docker has become the go-to solution for deploying, scaling, and managing containerized applications. Whether you're a developer, DevOps engineer, or systems administrator, mastering Docker CLI commands is essential for building efficient, portable, and resilient applications in modern cloud-native environments.
This expert tutorial on Docker Basic Commands on Linux is part of our Servers99 DevOps Essentials series, helping professionals streamline workflows on Linux-based infrastructure.
What You’ll Learn
- How to use essential Docker CLI commands
- Best practices for managing and monitoring Docker containers
- Real-world examples of container lifecycle operations
- Troubleshooting and Docker logs analysis techniques
Prerequisites
System | Linux (Ubuntu, Debian, CentOS, RHEL, or any Docker-compatible distro) |
---|---|
Software | Docker Engine & Docker CLI installed |
Internet | Required to pull images from Docker Hub |
Command Syntax | # - Run as root sudo;
$ - Run as regular user
|
Introduction to Docker CLI
Docker provides a powerful command-line interface that allows you to manage containers, images, networks, and volumes effortlessly. Containers act like lightweight virtual machines, encapsulating your application with all its dependencies, ensuring consistent performance across any environment.
Essential Docker Commands (With Examples)
1. List Running Containers
Copy Code
$ docker ps
Displays active containers, including names, IDs, uptime, and port mappings.
- Use
docker ps -a
to see all containers including stopped ones. -d
runs the container in the background.-
--name
assigns a human-readable name to your container. - You can specify a version/tag:
docker pull ubuntu:20.04
- If
/bin/bash
isn’t available, try/bin/sh
for minimal containers like Alpine or BusyBox.
2. Run a New Container
Copy Code
$ docker run -d --name mycontainer nginx
Launches an NGINX container in detached mode with a custom name.
3. Stop & Remove Containers
Copy Code
$ docker stop mycontainer && docker rm mycontainer
Stops and deletes the container in one go, freeing up resources.
4. Check Docker Daemon Status
Copy Code
$ systemctl status docker
Verifies if the Docker service is active. Use systemctl start docker
to manually start it if inactive.
5. Pull Images from Docker Hub
Copy Code
$ docker pull ubuntu
Downloads the latest official Ubuntu image from Docker Hub for local use.
6. View Container Logs
Copy Code
$ docker logs mycontainer
Displays STDOUT/STDERR logs of the container—critical for debugging applications in real-time.
7. Connect to a Running Container (Shell Access)
Copy Code
$ docker exec -it mycontainer /bin/bash
Starts an interactive terminal inside the container, useful for debugging or configuration.
Building Your Own Docker Image
Create a minimal Docker container that prints a message to the console.
Step 1: Create a Dockerfile
Copy Code
# Use BusyBox as the base image
FROM busybox
# Define command to run
CMD echo "LinuxConfig.org!"
Step 2: Build the Docker Image
Copy Code
$ docker build -t busybox-hello .
-t
tags the image with a name for easier reference.
Step 3: Run the Image
Copy Code
$ docker run --rm busybox-hello
--rm
auto-removes the container after it exits, ideal for one-time jobs.
Conclusion
Mastering Docker CLI commands equips you with the tools to build scalable, reproducible, and efficient systems whether for development, testing, or production deployments.
If you're running Docker on a dedicated server, be sure to configure resources like CPU and memory limits to optimize container performance. Check out our high-performance dedicated servers built for modern containerized workloads.