Notes of Docker

Install docker on Manjaro

sudo pacman -S docker
sudo pacman -Syyu

Run docker

systemctl start docker
systemctl enable docker

Config docker

sudo groupadd docker
sudo gpasswd -a $USER docker ## add logged-in user to the docker group
newgrp docker


sudo usermod -aG docker seashine

vim /etc/docker/daemon.json

  "graph": "/data/docker",
  "storage-driver": "overlay2",
  "insecure-registries": ["",""],
  "registry-mirrors": [""],
  "bip": "",
  "exec-opts": ["native.cgroupdriver=systemd"],
  "live-restore": true

sudo systemctl daemon-reload
sudo systemctl restart docker


docker login
The authentication information is stored at:
cat /root/.docker/config.json

Image operation

  • Show the list of images which are available locally
    docker images
    docker images -a
    docker images -q
    docker images -qa
    docker images --digest
    docker images --digest --no-trunc
  • Search the image in the repository
    docker search tomcat
    docker search -s 30 tomcat
    docker search -s 30 --no-trunc tomcat
  • Tag the specified image
    docker tag 965ea09ff2eb

docker push

docker rmi 965ea09ff2eb

  • If the image is referenced in multiple repostories, deletion must be forced
    docker rmi -f 965ea09ff2eb
  • delete all
    docker rmi -f $(docker images -qa)

Container operation

  • Create and run a container
    docker run -it [IMAGE ID]

    -i, --interactive Keep STDIN open even if not attached
    -t, --tty Allocate a pseudo-TTY
    Notes of Docker_第1张图片
  • Create and run a container, with another name specified
    docker run -it --name ABC [IMAGE]
  • Create and run a container in background
    docker run -d [IMAGE ID]
  • Show all the containers/processes running in docker
    docker ps
  • Show the most recently running container
    docker ps -l
  • Show the recent 6 running containers
    docker ps -l n 6
  • Exit the container and stop it
  • Exit the container without terminating it
    ctrl + P + Q
  • Start a container
    docker start [CONTAINER NAME/ID]
  • Stop a container
    docker stop [CONTAINER NAME/ID]
    docker kill [CONTAINER NAME/ID]
  • Stop multiple containers
    docker stop $(docker ps -p)
  • Remove a container
    docker rm [CONTAINER ID]
  • Remove multiple containers
    docker rm -f $(docker ps -q)
    docker rm -f $(docker ps -a -q)
    docker ps -a -q | xargs docker rm
  • Logs of a container
    docker logs -f -t --tail [CONTAINER ID]
  • Show detailed information of a container
    docker inspect [CONTAINER ID]
  • Run command on the host and outside of the container
    docker exec -t [CONTAINER NAME/ID] ls -l /tmp
  • Reenter the container after ctrl + P + Q
    docker attach [CONTAINER ID]
    docker exec -t [CONTAINER NAME/ID] /bin/bash
  • Copy a file of a container to the host
    docker cp [CONTAINER ID]:/tmp/yum.long /root

Run tomcat on host machine through port mapping

  • docker run -it -p [HOST PORT]:[IMAGE PORT] [IMAGE NAME]
    docker run -it -p 8888:8080 tomcat:8.0.41

    -p indicates that the port number afterwards is user-specified.
    8888 is the user-specified port number of host machine.

Notes of Docker_第2张图片

  • docker run -it -P [IMAGE NAME]
    docker run -it -P tomcat:8.0.41
    -P indicates that the port number afterwards is specified by host OS.


Notes of Docker_第3张图片

Modify an image

Notes of Docker_第4张图片

Notes of Docker_第5张图片

Notes of Docker_第6张图片

Create the modified image


Docker volumes