All About Technology

[email protected]

Have a question, comment, or concern? Our dedicated team of experts is ready to hear and assist you. Reach us through our social media, phone, or live chat.

+1 202 555 0180

Have a question, comment, or concern? Our dedicated team of experts is ready to hear and assist you. Reach us through our social media, phone, or live chat.

All About Technology
Basic Docker Commands for Beginners

Basic Docker Commands for Beginners

Docker has become an essential tool for developers and system administrators to build, ship, and run applications in isolated environments called containers. This article will walk you through the basic Docker commands with examples to help you get started with Docker on a Linux system.


1. Install Docker on Linux

To install Docker on a Linux system using the yum package manager, run the following command:

yum install docker -y

This command installs Docker and its dependencies. The -y flag automatically answers “yes” to any prompts during installation.

Check it out.! How to Install Docker


2. Check Docker Version

After installation, verify the Docker version to ensure it’s installed correctly:

docker --version

Example output:

Docker version 20.10.12, build e91ed57

3. Start Docker Service

To start the Docker service, use the following command:

service docker start

This command starts the Docker daemon, which is required to manage containers.


4. Check Docker Service Status

To verify whether the Docker service is running, use:

service docker status

Example output:

docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since ...

5. Check Docker Information

To view detailed information about the Docker installation, use:

docker info

This command provides details like the number of containers, images, storage drivers, and more.

Check it out.! Create Service on Docker Swarm And Container Replicas


6. List All Docker Images

To see all Docker images stored locally on your machine, use:

docker images

Example output:

REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
ubuntu       latest    123456789abc   2 weeks ago    72.8MB

7. Search for Images on Docker Hub

To search for images on Docker Hub, use:

docker search ubuntu

This command lists all publicly available Ubuntu images on Docker Hub.


8. Download an Image from Docker Hub

To download an image from Docker Hub to your local machine, use:

docker pull ubuntu

This command downloads the latest Ubuntu image.


9. Run a Docker Container

To download and run a Docker container in interactive mode, use:

docker run -it ubuntu /bin/bash

This command downloads the Ubuntu image (if not already present) and starts a container with a Bash shell.


10. Name a Docker Container

To assign a custom name to a container, use:

docker run -it --name my_container ubuntu /bin/bash

This command creates a container named my_container.


11. Start a Stopped Container

To start a stopped container, use:

docker start my_container

12. Attach to a Running Container

To access a running container, use:

docker attach my_container

This command allows you to interact with the container’s shell.


13. View Container OS Details

To check the operating system details inside a container, use:

cat /etc/os-release

Example output:

NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"

14. Exit a Container

To exit a container without stopping it, press Ctrl + P + Q. To stop and exit, use:

exit

15. List All Containers

To list all containers (running and stopped), use:

docker ps -a

16. List Running Containers

To list only running containers, use:

docker ps

17. List Exited Containers

To list only exited containers, use:

docker ps -q -f "status=exited"

18. Stop a Container

To stop a running container, use:

docker stop my_container

19. Delete a Container

To delete a stopped container, use:

docker rm my_container

20. Stop All Containers

To stop all running containers, use:

docker stop $(docker ps -a -q)

21. Delete All Stopped Containers

To delete all stopped containers, use:

docker rm $(docker ps -a -q)

22. Delete All Images

To delete all Docker images, use:

docker rmi -f $(docker images -q)

23. Rename a Container

To rename a Docker container, use:

docker rename old_container new_container

These Docker commands are essential for managing containers and images effectively. Whether you’re a beginner or an experienced user, mastering these commands will help you streamline your Docker workflow. Happy containerizing! 🐳

A big thank you for exploring TechsBucket! Your visit means a lot to us, and we’re grateful for your time on our platform. If you have any feedback or suggestions, we’d love to hear them.

Docker

Docker Commands

Basic Docker Commands

Basic Docker Commands for Beginners

Share this article
Shareable URL
Prev Post

Best gaming phones under Rs 20,000: 50MP Cameras, 6000mAh Battery!

Next Post

Nokia Premiere Pro Max specs: 200MP Camera, 7600mAh Battery!

Leave a Reply

Your email address will not be published. Required fields are marked *

Read next