Blog

  • Home
  • Docker
  • Docker Commands with Examples for Container Operations

Docker Commands with Examples for Container Operations

  • (4.0)
  • | 797 Ratings |
  • Last Updated October 27, 2017

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

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

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=)

Example

# 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

Commands
$ 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)

Example

# MySQL
$ 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
$ 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

$ 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 
    192.168.99.100:2377
$ docker info
$ docker-machine stop worker
$ docker-machine start worker

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 
    192.168.99.103:2377
$ 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:

Subscribe For Free Demo

Free Demo for Corporate & Online Trainings.


DMCA.com Protection Status