Advanced Docker Commands: Enhancing Containerization Mastery

Umar Farooque Khan
2 min readNov 15, 2023

--

Embarking on a journey with Docker reveals a world of sophisticated containerization capabilities. Beyond the fundamentals, mastering advanced Docker commands empowers developers and operators to harness greater control over containers, networks, and images. This curated collection extends the Docker toolkit, covering nuanced operations like resource management, health inspection, and efficient image handling. As we delve into this realm of advanced commands, we unlock the potential for streamlined workflows, optimized resource utilization, and a deeper understanding of Docker’s intricacies. Join us on this exploration of ‘Advanced Docker Commands: Enhancing Containerization Mastery’ for a comprehensive dive into Docker’s advanced features and best practices

  1. Run Container with Specific Name:
docker run --name my-container <image_name>

Assign a custom name to a running container.

2. Copy Files to/from Container:

docker cp <local_file_or_directory> <container_id>:<container_path> 
docker cp <container_id>:<container_path> <local_file_or_directory>

Copy files to or from a running container.

3. Run Container with Port Mapping:

docker run -p <host_port>:<container_port> <image_name>

Map a host port to a container port.

4. Inspect Container Health:

docker inspect --format='{{json .State.Health}}' <container_id>

Check the health status of a container.

5. Run Container with Resource Limits:

docker run --cpus=<value> --memory=<value> <image_name>

Set CPU and memory limits for a container.

6. Remove Dangling Images:

docker image prune -f

Remove all dangling (unused and untagged) images.

7. Build and Tag Image:

docker build -t <repository>/<image_name>:<tag> <path_to_Dockerfile>

Build an image and tag it for a specific repository and version.

8. Docker Stats:

docker stats <container_id>

Display real-time usage statistics for a container.

9. Container Top Processes:

docker top <container_id>

Display the running processes inside a container.

10. Run Container with Environment File:

docker run --env-file <path_to_env_file> <image_name>

Set environment variables from a file while running a container.

Conclusion:

These commands expand your Docker toolkit, providing more control over containers, images, and the overall Docker environment. Adjust them according to your specific needs and use cases.

--

--

Umar Farooque Khan
Umar Farooque Khan

Written by Umar Farooque Khan

Experienced software developer with a passion for clean code and problem-solving. Full-stack expertise in web development. Lifelong learner and team player.

No responses yet