DEV Community

Abhijith
Abhijith

Posted on

10

Getting Started with Docker: Essential Commands for Beginners

So you're venturing into the realm of Docker? Great choice! This technology is a game changer for developers, making it incredibly simple to package and run apps in containers.

To help you started, here are some important Docker commands you'll commonly use.

1. Installing Docker

Before you start, make sure Docker is installed on your machine. You can follow the official installation guide for Docker Desktop.

2. Basic Docker Commands

docker --version

This command verifies your Docker installation by checking the installed version.

docker pull <image_name>

This command pulls a Docker image from the Docker Hub repository.

docker run <image_name>

This command creates and runs a container from a Docker image. To run container in detached mode add -d flag.
To map container port to local ports add -p flag.

Example:
docker run -d -p 8080:80 nginx

Enter fullscreen mode Exit fullscreen mode

This runs nginx container in port 8080 in detached mode(Runs in background i.e. No terminal will be tied to it).(We are mapping container port 80 to our local port 8080)

docker ps

This shows all running containers. Use docker ps -a to see all containers, including those that are stopped.

docker images

This command lists all Docker images downloaded to your local machine.

3. Commands to Manage Containers

docker stop <container_id>

This command stops a running container.

docker start <container_id>

This command starts a stopped container.

docker logs <container_id>

This command is used to show logs of a running container.

docker restart <container_id>

This command restarts a running container.

docker rm <container_id>

This command deletes a stopped container. Use -f to force remove a running container.

(You can replace with the actual container ID or name.)

docker rmi <image_name>

This command deletes an image from local machine. Used to free up space.

docker system prune

This command cleans up all stopped containers, dangling images, and unused networks.

Docker makes it easy to package and deploy applications. If you master these commands, it will give you a solid foundation as you begin exploring more advanced features. Any questions ask them below.

Happy Dockerizing!

Neon image

Build better on Postgres with AI-Assisted Development Practices

Compare top AI coding tools like Cursor and Windsurf with Neon's database integration. Generate synthetic data and manage databases with natural language.

Read more →

Top comments (4)

Collapse
 
thwitcher223344 profile image
Witcher

Nice 👍

Collapse
 
merlin_varghese profile image
Merlin Varghese

Insightful post!

Collapse
 
sandeep_pradeep_7afbd2d14 profile image
Sandeep pradeep

Thanks for the blog

Collapse
 
roja_babyrobins_f5c55f6b profile image
Roja Baby Robins

Great👍

Jetbrains image

Build Secure, Ship Fast

Discover best practices to secure CI/CD without slowing down your pipeline.

Read more

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay