Home > Other External Packages > docker

Docker Command Guide

Docker is a container-based virtualization platform that helps you deploy and run applications quickly and reliably. Learn the key Docker commands with this guide.

Docker Installation

Before using Docker, you need to install it on your system. Here are the installation methods for major operating systems.

Install Docker on Ubuntu/Debian

This is how to install Docker on Ubuntu or Debian-based systems. It is recommended to remove any previously installed Docker versions first.

Remove old Docker packages

sudo apt-get remove docker docker-engine docker.io containerd runc

Removes any previously installed Docker-related packages.

Install necessary packages for Docker

sudo apt-get update
sudo apt-get install ca-certificates curl gnupg

Installs the dependency packages required for Docker installation.

Add Docker's official GPG key

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

Adds the GPG key for the Docker APT repository to ensure package authenticity.

Set up the Docker APT repository

echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Adds the APT repository to your system to download Docker packages.

Install Docker Engine

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Installs the latest Docker Engine, containerd, and Docker Compose.

Verify Docker installation

sudo docker run hello-world

Runs the 'hello-world' image to verify that Docker is installed correctly.

Use Docker without sudo (optional)

To run Docker commands without using `sudo` every time, you need to add your current user to the `docker` group. This change will take effect after you log out and log back in.

Add user to docker group

sudo usermod -aG docker ${USER}

Adds the current user to the `docker` group.

Main Docker Commands

These are the core commands used to manage Docker containers, images, volumes, and more. Combine each option to perform the desired tasks.

1. Container Management

2. Image Management

3. Network and Volume Management

4. System Management

Generated command:

Try combining the commands.

Description:

`docker` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Manage your container environment effectively with these practical examples of Docker commands.

Run an Nginx web server container

docker run -d --name my-nginx -p 80:80 nginx

Runs an Nginx web server container in the background, accessible on port 80. The container name is 'my-nginx'.

Access inside a container (bash shell)

docker exec -it my-nginx bash

Connects to the bash shell inside the running 'my-nginx' container. (Useful for working inside the container)

Force remove a specific container

docker rm -f my-container

Forcefully removes a container named 'my-container', whether it is running or stopped.

Build a Docker image and tag it

docker build -t my-app:v1.0 .

Builds a Docker image named 'my-app' using the Dockerfile in the current directory. The tag is 'v1.0'.

Remove all stopped containers

docker rm $(docker ps -aq)

Removes all stopped containers that are no longer in use to free up disk space.


Same category commands