1. 在当前目录创建镜像
1
docker build -t newImage . 
  1. 运行nginx映射本地端口4000映射容器内80端口
1
docker run -p 8080:80 nginx
  1. 容器相关
  • 查看运行中的容器
1
docker container ls
  • 查看所有的容器
1
docker container ls - a
  • 优雅的关闭一个容器
1
docker container stop <hash>
  • 强制关闭一个容器
1
docker container kill <hash>
  • 从设备中移除指定的容器
1
docker container rm <hash>
  • 从设备中移除所有的容器
1
docker container rm $(docker container ls -a -q)
  1. 镜像相关
  • 查看所有的镜像
1
docker image ls -a
  • 移除指定的对象
1
docker image rm <image id>
  • 移除所有的镜像
1
docker image rm $(docker image ls -a -q)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
docker build -t friendlyhello . 
docker run -p 4000:80 friendlyhello  # Run "friendlyname" mapping port 4000 to 80
docker run -d -p 4000:80 friendlyhello         # Same thing, but in detached mode
docker container ls                                # List all running containers
docker container ls -a             # List all containers, even those not running
docker container stop <hash>           # Gracefully stop the specified container
docker container kill <hash>         # Force shutdown of the specified container
docker container rm <hash>        # Remove specified container from this machine
docker container rm $(docker container ls -a -q)         # Remove all containers
docker image ls -a                             # List all images on this machine
docker image rm <image id>            # Remove specified image from this machine
docker image rm $(docker image ls -a -q)   # Remove all images from this machine
docker login             # Log in this CLI session using your Docker credentials
docker tag <image> username/repository:tag  # Tag <image> for upload to registry
docker push username/repository:tag            # Upload tagged image to registry
docker run username/repository:tag                   # Run image from a registry
docker exec -it container /bin/bash # exec in bash
docker logs:查看容器的日志,例如:docker logs container_name。
docker inspect:查看容器的详细信息,例如:docker inspect container_name。