Docker 基本コマンド

Dockerのコマンドは長くなりがち

Doker build

    docker build . -t <tag_name>

Docker run

docker run -itd --privileged -v <host_dir>:<container_dir> -p <host_port>:<container_port> --name <container_name> <image_tag>
#example
docker run -itd --privileged -v /home/vagrant/workspace/develop/ansible/Develop_on_ubuntu/ansible:/ansible  -p 2223:22 --name dev dev

Container stop remove

docker stop $(docker ps -q)
docker rm -f  <container_name>
docker rm $(docker ps -q -a)  # all container
docker rmi $(docker images -q) # all image

Docker exec

# basic
docker exec -it <container_name> bash

Options

  • -u ‘username’
  • -d ‘background’
  • -e ‘env’
  • —privileged
  • -w ‘workdir’

Create Network

docker network create <network_name>
# subnet
docker network create --driver=bridge --subnet=172.30.0.0/24 dev

Volumes

docker volume ls

Remove Volumes

docker volume rm <volume_name>

Get IP from container

docker inspect <コンテナID>

Clean UP

Imagge

docker image prune

container

docker container prune

おっさんWEBエンジニア奮闘記©2007 WEBDIMENSION