0%

docker notes

Container operations

  1. docker ps -> running container
  2. docker ps -a -> all containers including stopped ones
  3. docker run
    [-d#Background running#]
    [–name=]
    [-rm#Clean container after stopping#]
    [-p #Open port<3000/tcp|4000/udp>#]
    [-e ]
    :v
  4. docker exec [-it#interact#] -> execute shell command in the container
  5. docker attach -> Not recommended, attach to container shell
  6. docker start|stop|restart -> start, stop and restart the container
  7. docker rm $(docker ps -a|grep Created|awk ‘{print $1}’) -> Delete the container that failed to start

Mirror operation

  1. docker commit [-a “author name”] [-m “information description”] :v -> Submit the container into a mirror
  2. docker images -> View all current images
  3. docker save -o -v.tar :v -> package the image in tar compression format
  4. docker load -i -v.tar -> Unzip the image tar and import it
  5. docker system df -v -> Check the disk occupied by the image
  6. docker export -o .tar -> Export the image directly from the container to avoid the image becoming larger after multiple commits.
  7. docker import :v -> The image exported through export must be imported through import

Other commands

  1. Docker system prune –volumes -> You can clean the cache after the save fails.
  2. docker system prune -a -> If the above one does not work, you can use this one to clean it all. The image and container will be lost.
  3. dockerd –iptables=false -> An error will be reported when running under wsl. Use this to disable the firewall.

Install docker on ubuntu20.4

  1. apt-get install ca-certificates curl gnupg lsb-release
  2. mkdir -p /etc/apt/keyrings
  3. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg –dearmor -o /etc/apt/keyrings/docker.gpg
  4. echo “deb [arch=$(dpkg –print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs ) stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  5. apt-get update
  6. apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin