Common Docker Commands

tomislavkraljic

Tomislav Kraljic

Posted on June 21, 2021

Common Docker Commands

Hey y'all! In this article, I will go over a lot of the main/common docker commands and what they do.

Let's get started!

docker images - This displays all the images installed on your machine. It contains a lot of important information such as tag, size, image id, and the repository installed.

docker ps - This displays all the containers currently running at the moment. This is super helpful if we want to go inside the container and access/configure some data.

docker pull <image> - This will pull a docker image from a repository. This could be from DockerHub, Nexus, AWS ECR, etc.

docker run -d - This will run the docker image in "detached" mode. This means that it will be running in the background.

docker stop <container_id> - This will stop the container from being executed.

You should be aware that if the container is running a application with data saved/configured, all the data will be lost when you stop the container. To fix this, use Docker Volumes.

docker run <image> - This will create a new container to run an image and execute the container.

docker start <container_id> This will launch the already existing container.

docker log <container_id> - This will retrieve logs of the container running. This is great for debugging!

docker exec -it <container_id> bin/bash - This enables you to go inside the container that is running and run commands, check configs, environment variables, etc.

If /bin/bash doesn't work, use /bin/sh

docker run -p <new_port>:<container_port> - This allows you to run the container on a separate host port.

docker build -t <name_of_image>:<tag> - This will build the image.

docker push <repository>:<tag> - This will push your docker image.

docker tag <image>:<tag> <new_image>:<new_tag> - This will allow you to rename your image and create of copy of it.

docker volume create --name <name> - This will allow you to create a volume and give it a custom name.

💖 💪 🙅 🚩
tomislavkraljic
Tomislav Kraljic

Posted on June 21, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related