1.建立鏡像
docker build -t friendlyname . # Create image using this directory's Dockerfile
2.運行friendlyhello,docker內部的端口映射到宿主機的4000,我們訪問應用用4000
docker run -p 4000:80 friendlyname # Run "friendlyname" mapping port 4000 to 80
3.后臺的方式運行
docker run -d -p 4000:80 friendlyname # Same thing, but in detached mode
4.查看運行的容器
docker ps # See a list of all running containers
5.停止運行的容器,id通過 docker ps查看
docker stop <hash> # Gracefully stop the specified container
6.查看所有的容器不管是否運行的
docker ps -a # See a list of all containers, even the ones not running
- 強制殺死指定的容器
docker kill <hash> # Force shutdown of the specified container
8.從機器移除指定的容器
docker rm <hash> # Remove the specified container from this machine
9.移除機器所有的容器
docker rm $(docker ps -a -q) # Remove all containers from this machine
10.顯示本機包含的所有的鏡像
docker images -a # Show all images on this machine
11.從本季移除制定的鏡像
docker rmi <imagename> # Remove the specified image from this machine
12.從本機移除所有的鏡像
docker rmi $(docker images -q) # Remove all images from this machine
13.cli下登錄docker帳號
docker login # Log in this CLI session using your Docker credentials
14.標記要上傳到倉庫的鏡像
docker tag <image> username/repository:tag # Tag <image> for upload to registry
15.推送docker鏡像到倉庫
docker push username/repository:tag # Upload tagged image to registry
16.從倉庫運行docker鏡像
docker run username/repository:tag # Run image from a registry
docker stack ls # List all running applications on this Docker host
docker stack deploy -c <composefile> <appname> # Run the specified Compose file
docker stack services <appname> # List the services associated with an app
docker stack ps <appname> # List the running containers associated with an app
docker stack rm <appname> # Tear down an application