Docker Commands with Examples for Container Operations

Very useful docker commands with examples for container operations. Here we are presenting a list of docker commands for Image, Container, Volume, Network, docker-compose, docker-machine, Swarm.

Image Docker Commands

$ docker build --tag .
$ docker build --tag --no-cache .
$ docker images
$ docker images :
ex) docker images mysql:latest
$ docker rmi

I think that it is common when wanting to erase it collectively

# Unused Image
$ docker rmi $(docker images -f "dangling=true" -q)

# Repository specification
$ docker images {REPOSITORY_NAME} -aq | xargs docker rmi

Learn how to use Docker, from beginner basics to advanced techniques, with online video tutorials taught by industry experts. Enroll for Free Docker Training Demo!

Container Docker Commands

$ docker run --name -it
$ docker run -td --net
$ docker ps -a
$ docker exec -it bash

# System to erase collectively
$ docker rm $(docker ps -aq)
$ docker rm $(docker ps -aq --filter name=)


# MySQL With Password
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=password -d mysql:latest
$ do exec -it some-mysql bash

# MySQL Without Password
$ docker run --name some-mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -d mysql:latest

Volume Docker Interview Questions

$ docker volume create --name
$ docker volume ls
$ docker volume rm

# System to erase collectively
$ docker volume rm $(docker volume ls --filter name= -q)
$ docker volume rm $(docker volume ls -f dangling=true -q)


$ docker volume create --name hoge
$ docker run --name piyo -d -v hoge:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=pw mysql
$ docker exec -it piyo bash

Frequently Asked Docker Interview Questions & Answers

Network Docker Commands

$ docker network ls
$ docker network inspect
$ docker-compose build
$ docker-compose up
$ docker-compose --project-name= up -d
$ docker-compose ps
$ docker-compose stop
$ docker-compose start
$ docker-compose -f up
$ docker-compose exec bash
$ docker-compose rm

# Check log
$ docker-compose logs


$ docker-machine create -d virtualbox manager

$ docker-machine create 
  --driver amazonec2 --amazonec2-region ap-northeast-1 --amazonec2-vpc-id vpc-02c94966 
  --amazonec2-subnet-id subnet-4bcd853d mochizukitest02

$ ll ~/.docker/machine/machines
$ docker-machine ls
$ docker-machine ip manager
$ docker-machine create -d virtualbox worker
$ docker-machine ssh worker
$ docker swarm join 
    --token SWMTKN-1-26vtuh7mtfofdxkj721ap6eftvqw2i3dsd7yrp5vlsft2t2xzu-8sjf8e5z1aojs3l4htw3r0wg7
$ docker info
$ docker-machine stop worker
$ docker-machine start worker

MindMajix YouTube Channel

Swarm Docker Commands

$ docker-machine ip manager

$ docker ssh manager
$ docker swarm init --advertize-addr
$ docker swarm join-token manager

$ docker ssh worker
$ docker swarm join 
    --token SWMTKN-1-1ydb7x3wyc4ong1y08we9smq61672en9z851rkytcbmfwhj282-1hftyp3smd45bm78k0o33fzp1
$ docker node ls
$ docker swarm leave

# stack
$ docker-machine ssh manager
$ docker stack deploy --compose-file docker-stack.yml vote
$ docker stack services vote

Explore Docker Sample Resumes! Download & Edit, Get Noticed by Top Employers!Download Now!


List Of MindMajix Docker Courses:

 Kubernetes Administration
 Docker Kubernetes
 OpenShift Administration
Course Schedule
Docker TrainingJun 22 to Jul 07View Details
Docker TrainingJun 25 to Jul 10View Details
Docker TrainingJun 29 to Jul 14View Details
Docker TrainingJul 02 to Jul 17View Details
Last updated: 03 Apr 2023
About Author

Vinod M is a Big data expert writer at Mindmajix and contributes in-depth articles on various Big Data Technologies. He also has experience in writing for Docker, Hadoop, Microservices, Commvault, and few BI tools. You can be in touch with him via LinkedIn and Twitter.

read less