Docker commands for beginners | Saksham Khandelwal

Post

editor-img
Saksham Khandelwal
Jan 27, 2023

Docker commands for beginners

Docker is a tool that allows software developers to easily create, deploy, and run applications in containers. Containers provide a consistent environment for software to run in, making it easy to develop and test applications on a developer’s local machine, and then deploy them to a production environment.

media

To effectively use Docker, it’s important for software developers to understand the basic commands that are used to manage containers and images. In this post, I will cover some of the most commonly used Docker commands that every software developer should know. I will explain what each command does, and provide examples of how to use them.

By the end of this post, you will have a solid understanding of how to use Docker and be able to confidently work with containers and images.

Here are some basic Docker commands that every software developer should know:

1. docker run: This is one of the most important and often used command. It is used to run a container from a specific image. For example, if you wanted to run an Ubuntu container, you would use the command docker run -it ubuntu. The -it flag tells Docker to run the container in interactive mode and to allocate a pseudo-TTY.

2. docker pull: This command is used to download an image from a registry. For example, if you wanted to download the latest version of the Ubuntu image from the Docker Hub registry, you would use the command docker pull ubuntu.

3. docker images: In order to list all of the images on your local machine, you can use this command.

4. docker ps: This command is straight forward. Use it to list all of the running containers on your local machine.

5. docker stop: Stopping a running container can be achieved with this command. For example, if you wanted to stop a container with the ID of abc123, you would use the command docker stop abc123.

6. docker rm: For removing a container. Let’s say you want to remove a container with the ID of abc123, you would use the command docker rm abc123.

7. docker rmi: This command is used to remove an image, e.g. , if you wanted to remove an image with the ID of abc123, you would use the command docker rmi abc123.

8. docker build: In order to build an image from a Dockerfile, you use this command. For example, if you had a Dockerfile in the current directory, you would use the command docker build -t abc123 . to build an image named "abc123".

9. docker tag: Adding a tag to an image can be achieved with this command. For example, if you wanted to add a tag of “latest” to an image with the ID of abc123, you would use the command docker tag abc123 my-image:latest.

10. docker push: In order to push an image to a registry.

For example, if you wanted to push an image named “abc123” to the Docker Hub registry, you would use the command docker push abc123.

11. docker exec: This command is used to execute a command within a running container. For example, you wanted to execute the command ls within a container with the ID of abc123, you would use the command docker exec abc123 ls.

12. docker inspect: If you want to know detailed information about a container or image, use this command. For example, if you wanted to see detailed information about an image with the ID of abc123, you would use the command docker inspect abc123.

If these commands don’t run in your terminal, then it’s probably because you are missing some privileges. In this kind of case you may try to precede the commands with sudo.