由於此網站是由docker建立的,在過程中也學習到很多docker command,但由於指令太多,且很多時候需要搭配一些範例才比較容易了解,因此寫下此篇文章作為紀錄。
基本指令
docker pslist running containers.docker ps -alist all container including stopped containerdocker pulldownload a image from Docker Hub registry. Link to the docker image is always shown on the right at dockerhub.docker buildis used to build your own container based on a Dockerfile. Common use is docker build . to build a container based on the Dockerfile in the current directory (the dot). docker build -t "myimage:latest" . creates a container and stores the image under the given namedocker imagesordocker image lsshows all local storage imagesdocker runRun a docker container based on an image, i. e. docker run myimage -it bash. If no local image can be found docker run automatically tries to download the image from Docker hub.docker logsdisplay the logs of a container, you specified. To continue showing log updates just use docker logs -f mycontainerdocker volume lslists the volumes, which are commonly used for persisting data of Docker containers.docker network lslist all networks available for docker containerdocker network connectadds the container to the given container network. That enables container communication by simple container name instead of IP.docker rmremoves one or more containers. docker rm mycontainer, but make sure the container is not runningdocker rmiremoves one or more images. docker rmi myimage, but make sure no running container is based on that imagedocker stopstops one or more containers. docker stop mycontainer stops one container, while docker stop $(docker ps -a -q) stops all running containers.docker startstarts a stopped container using the last state
docker update --restart=noupdates container policies, that is especially helpful when your container is stuck in a crash loop.docker cpto copy files from a running container to the host or the way around. docker cp :/etc/file . to copy /etc/file to your current directory.