Basic docker commands

Docker commands to get started

Here is a list of some commonly used Docker commands along with brief explanations that can help you get started with Docker:

  1. docker run: This command is used to run a Docker container based on a specific image. It creates and starts a new container instance from the specified image.

  2. docker pull: It pulls or downloads a Docker image from a registry, such as Docker Hub or a private registry. This is the first step before running a container based on that image.

  3. docker images: This command lists all the Docker images that are currently available on your system. It provides information such as the image ID, repository, tag, and size.

  4. docker ps: It lists all the running Docker containers on your system. By default, it shows the container ID, image used, command being run, status, and ports.

  5. docker stop: It stops a running container by specifying either the container ID or the container name.

  6. docker rm: This command is used to remove one or more containers from your system. It requires specifying the container ID or container name.

  7. docker rmi: It removes one or more Docker images from your system. You can specify the image ID or image name to remove.

When you execute the docker run command, Docker will look for the specified image locally on your system. If the image is not found locally, Docker will automatically pull it from a registry (such as Docker Hub) before creating the container.

When you use the docker rm command to remove a container, Docker automatically stops the container gracefully if it is running and then proceeds to remove it.

If you remove the image that was used to create a running container using the docker rmi command, the container will continue to run normally, unaffected by the removal of the image.

It's important to note that if you remove an image and later want to recreate or restart a container based on that image, Docker will not be able to pull the image again because it no longer exists locally.

Last updated