Skip to content

Instantly share code, notes, and snippets.

@hsn0x
Last active February 8, 2023 03:14
Show Gist options
  • Save hsn0x/2043f7656744c5f36257dc67af6f7864 to your computer and use it in GitHub Desktop.
Save hsn0x/2043f7656744c5f36257dc67af6f7864 to your computer and use it in GitHub Desktop.
Docker commands

List of all Docker commands

Created by @hsn0x

Build docker image

docker build -t <image_name> .

Run docker image

docker run -it <image_name>

Run docker image with port mapping

docker run -it -p <host_port>:<container_port> <image_name>

Run docker image with volume mapping

docker run -it -v <host_dir>:<container_dir> <image_name>

Run docker image with volume mapping and port mapping

docker run -it -p <host_port>:<container_port> -v <host_dir>:<container_dir> <image_name>

Run docker image with name

docker run -it --name <container_name> <image_name>

Run docker image with name and port mapping

docker run -it --name <container_name> -p <host_port>:<container_port> <image_name>

Run docker image with name and volume mapping

docker run -it --name <container_name> -v <host_dir>:<container_dir> <image_name>

Run docker image with name, volume mapping and port mapping

docker run -it --name <container_name> -p <host_port>:<container_port> -v <host_dir>:<container_dir> <image_name>

Run docker image with name, volume mapping, port mapping and environment variables

docker run -it --name <container_name> -p <host_port>:<container_port> -v <host_dir>:<container_dir> -e <env_var_name>=<env_var_value> <image_name>

Run docker image with name, volume mapping, port mapping, environment variables and detach mode

docker run -it --name <container_name> -p <host_port>:<container_port> -v <host_dir>:<container_dir> -e <env_var_name>=<env_var_value> -d <image_name>

Run docker image with name, volume mapping, port mapping, environment variables, detach mode and restart policy

docker run -it --name <container_name> -p <host_port>:<container_port> -v <host_dir>:<container_dir> -e <env_var_name>=<env_var_value> -d --restart=always <image_name>

Run docker image with name, volume mapping, port mapping, environment variables, detach mode, restart policy and network

docker run -it --name <container_name> -p <host_port>:<container_port> -v <host_dir>:<container_dir> -e <env_var_name>=<env_var_value> -d --restart=always --network=<network_name> <image_name>

Run docker image with name, volume mapping, port mapping, environment variables, detach mode, restart policy, network and link

docker run -it --name <container_name> -p <host_port>:<container_port> -v <host_dir>:<container_dir> -e <env_var_name>=<env_var_value> -d --restart=always --network=<network_name> --link <container_name>:<alias> <image_name>

Run docker image with name, volume mapping, port mapping, environment variables, detach mode, restart policy, network, link and hostname

docker run -it --name <container_name> -p <host_port>:<container_port> -v <host_dir>:<container_dir> -e <env_var_name>=<env_var_value> -d --restart=always --network=<network_name> --link <container_name>:<alias> --hostname <hostname> <image_name>

Remove all docker containers

docker rm $(docker ps -a -q)

Remove all docker images

docker rmi $(docker images -q)

Remove all docker volumes

docker volume rm $(docker volume ls -q)

Remove all docker networks

docker network rm $(docker network ls -q)

Remove all docker containers, images, volumes and networks

docker rm $(docker ps -a -q) && docker rmi $(docker images -q) && docker volume rm $(docker volume ls -q) && docker network rm $(docker network ls -q)

Remove docker container

docker rm <container_name>

Remove docker image

docker rmi <image_name>

Remove docker volume

docker volume rm <volume_name>

Remove docker network

docker network rm <network_name>

Remove docker container, image, volume and network

docker rm <container_name> && docker rmi <image_name> && docker volume rm <volume_name> && docker network rm <network_name>

Stop all docker containers

docker stop $(docker ps -a -q)

Stop docker container

docker stop <container_name>

Start all docker containers

docker start $(docker ps -a -q)

Start docker container

docker start <container_name>

Restart all docker containers

docker restart $(docker ps -a -q)

Restart docker container

docker restart <container_name>

Create docker volume

docker volume create <volume_name>

Create docker network

docker network create <network_name>

Create docker container with name and port mapping

docker create --name <container_name> -p <host_port>:<container_port> <image_name>

Create docker container with name, port mapping and environment variables

docker create --name <container_name> -p <host_port>:<container_port> -e <env_var_name>=<env_var_value> <image_name>

Create docker container with name, volume mapping, port mapping and environment variables

docker create --name <container_name> -p <host_port>:<container_port> -v <host_dir>:<container_dir> -e <env_var_name>=<env_var_value> <image_name>

Create docker container with name, volume mapping, port mapping, environment variables and restart policy

docker create --name <container_name> -p <host_port>:<container_port> -v <host_dir>:<container_dir> -e <env_var_name>=<env_var_value> --restart=always <image_name>

Create docker container with name, volume mapping, port mapping, environment variables, restart policy and network

docker create --name <container_name

List all docker containers

docker ps -a

List all docker images

docker images

List all docker volumes

docker volume ls

List all docker networks

docker network ls

List all docker containers, images, volumes and networks

docker ps -a && docker images && docker volume ls && docker network ls

List all docker containers with name

docker ps -a --format "table {{.ID}}\t{{.Names}}"

List all docker images with name

docker images --format "table {{.ID}}\t{{.Repository}}"

List all docker volumes with name

docker volume ls --format "table {{.Driver}}\t{{.Name}}"

List all docker networks with name

docker network ls --format "table {{.Driver}}\t{{.Name}}"

List all docker containers, images, volumes and networks with name

docker ps -a --format "table {{.ID}}\t{{.Names}}" && docker images --format "table {{.ID}}\t{{.Repository}}" && docker volume ls --format "table {{.Driver}}\t{{.Name}}" && docker network ls --format "table {{.Driver}}\t{{.Name}}"

List all docker containers with name and port mapping

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"

List all docker containers with name, port mapping and volume mapping

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Mounts}}"

List all docker containers with name, port mapping, volume mapping and status

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Mounts}}\t{{.Status}}"

List all docker containers with name, port mapping, volume mapping, status and restart policy

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Mounts}}\t{{.Status}}\t{{.RestartPolicy}}"

List all docker containers with name, port mapping, volume mapping, status, restart policy and network

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Mounts}}\t{{.Status}}\t{{.RestartPolicy}}\t{{.Networks}}"

List all docker containers with name, port mapping, volume mapping, status, restart policy, network and image

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Mounts}}\t{{.Status}}\t{{.RestartPolicy}}\t{{.Networks}}\t{{.Image}}"

List all docker containers with name

docker ps -a --format "table {{.ID}}\t{{.Names}}"

List all docker images with name

docker images --format "table {{.ID}}\t{{.Repository}}"

List all docker volumes with name

docker volume ls --format "table {{.Driver}}\t{{.Name}}"

List all docker networks with name

docker network ls --format "table {{.Driver}}\t{{.Name}}"

List all docker containers, images, volumes and networks with name

docker ps -a --format "table {{.ID}}\t{{.Names}}" && docker images --format "table {{.ID}}\t{{.Repository}}" && docker volume ls --format "table {{.Driver}}\t{{.Name}}" && docker network ls --format "table {{.Driver}}\t{{.Name}}"

List all docker containers with name and port mapping

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"

List all docker containers with name, port mapping and volume mapping

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Mounts}}"

List all docker containers with name, port mapping, volume mapping and status

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Mounts}}\t{{.Status}}"

List all docker containers with name, port mapping, volume mapping, status and restart policy

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Mounts}}\t{{.Status}}\t{{.RestartPolicy}}"

List all docker containers with name, port mapping, volume mapping, status, restart policy and network

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Mounts}}\t{{.Status}}\t{{.RestartPolicy}}\t{{.Networks}}"

List all docker containers with name, port mapping, volume mapping, status, restart policy, network and image

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Mounts}}\t{{.Status}}\t{{.RestartPolicy}}\t{{.Networks}}\t{{.Image}}"

List all docker containers with name, port mapping, volume mapping, status, restart policy, network, image and environment variables

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Mounts}}\t{{.Status}}\t{{.RestartPolicy}}\t{{.Networks}}\t{{.Image}}\t{{.Env}}"

List all docker containers with name, port mapping, volume mapping, status, restart policy, network, image, environment variables and command

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Mounts}}\t{{.Status}}\t{{.RestartPolicy}}\t{{.Networks}}\t{{.Image}}\t{{.Env}}\t{{.Command}}"

List all docker containers with name, port mapping, volume mapping, status, restart policy, network, image, environment variables, command and labels

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Mounts}}\t{{.Status}}\t{{.RestartPolicy}}\t{{.Networks}}\t{{.Image}}\t{{.Env}}\t{{.Command}}\t{{.Labels}}"

List all docker containers with name, port mapping, volume mapping, status, restart policy, network, image, environment variables, command, labels and state

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Mounts}}\t{{.Status}}\t{{.RestartPolicy}}\t{{.Networks}}\t{{.Image}}\t{{.Env}}\t{{.Command}}\t{{.Labels}}\t{{.State}}"

List all docker containers with name, port mapping, volume mapping, status, restart policy, network, image, environment variables, command, labels, state and health

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Mounts}}\t{{.Status}}\t{{.RestartPolicy}}\t{{.Networks}}\t{{.Image}}\t{{.Env}}\t{{.Command}}\t{{.Labels}}\t{{.State}}\t{{.Health}}"

List all docker containers with name, port mapping, volume mapping, status, restart policy, network, image, environment variables, command, labels, state, health and host config

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}\t{{.Mounts}}\t{{.Status}}\t{{.RestartPolicy}}\t{{.Networks}}\t{{.Image}}\t{{.Env}}\t{{.Command}}\t{{.Labels}}\t{{.State}}\t{{.Health}}\t{{.HostConfig}}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment