0 help使用
- 使用
docker help
查看docker能够使用的命令 - 使用
docker help run
查看具体命令的使用
功能详解
info
Display system-wide informationlogin
Log in to a Docker registrylogout
Log out from a Docker registryversion
Show the Docker version information
1 镜像操作
- 查找镜像:
docker search 镜像名
- 拉取镜像:
docker pull 镜像名[:版本号]
- 示例:
docker pull tomcat
docker pull tomcat:9.0
- 说明:不带tag,默认拉取tag为
latest
的镜像,即docker pull tomcat
和docker pull tomcat:latest
拉取的是同一个镜像
- 示例:
- 查看本地镜像:
docker images
- 查看镜像信息:
docker inspect 镜像id
docker inspect 镜像名称[:版本号]
- 删除镜像:
docker rmi 镜像id
docker rmi 镜像名称[:版本号]
功能详解
build
Build an image from a Dockerfilehistory
Show the history of an imageimages
List imagesimport
Import the contents from a tarball to create a filesystem imageinspect
Return low-level information on Docker objectsload
Load an image from a tar archive or STDINpull
Pull an image or a repository from a registrypush
Push an image or a repository to a registryrmi
Remove one or more imagessave
Save one or more images to a tar archive (streamed to STDOUT by default)search
Search the Docker Hub for imagestag
Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
2 容器操作
- 启动容器:
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
- 启动centos:
docker run -it centos:7
,按Ctrl+P+Q可以不停止退出 - 启动nginx:
docker run --name nginx80 -p 80:80 -d nginx
- 启动mysql:
docker run -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 --rm -d mysql:8.0.19
Options: --add-host list Add a custom host-to-IP mapping (host:ip) --cap-add list Add Linux capabilities --cap-drop list Drop Linux capabilities --cpus decimal Number of CPUs --device-cgroup-rule list Add a rule to the cgroup allowed devices list --dns list Set custom DNS servers --domainname string Container NIS domain name --entrypoint string Overwrite the default ENTRYPOINT of the image -e, --env list Set environment variables -h, --hostname string Container host name -i, --interactive Keep STDIN open even if not attached --ip string IPv4 address (e.g., 172.30.100.104) --kernel-memory bytes Kernel memory limit -l, --label list Set meta data on a container --link list Add link to another container --link-local-ip list Container IPv4/IPv6 link-local addresses --name string Assign a name to the container --network network Connect a container to a network --privileged Give extended privileges to this container -p, --publish list Publish a container's port(s) to the host -P, --publish-all Publish all exposed ports to random ports --pull string Pull image before running ("always"|"missing"|"never") (default "missing") --read-only Mount the container's root filesystem as read only --restart string Restart policy to apply when a container exits (default "no") --rm Automatically remove the container when it exits -t, --tty Allocate a pseudo-TTY -u, --user string Username or UID (format: <name|uid>[:<group|gid>]) -v, --volume list Bind mount a volume --volumes-from list Mount volumes from the specified container(s) -w, --workdir string Working directory inside the container
- 启动centos:
- 容器列表:
docker ps [OPTIONS]
- 显示正在运行的容器:
docker ps
- 显示所有状态的容器:
docker ps -a
- 显示所有容器的id:
docker ps -aq
Options: -a, --all Show all containers (default shows just running) -f, --filter filter Filter output based on conditions provided --format string Pretty-print containers using a Go template -n, --last int Show n last created containers (includes all states) (default -1) -l, --latest Show the latest created container (includes all states) --no-trunc Don't truncate output -q, --quiet Only display container IDs -s, --size Display total file sizes
- 显示正在运行的容器:
- 容器中执行命令:
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
- 进入容器:
docker exec -it 容器名 /bin/bash
- 执行命令:
docker exec 容器名 cat /etc/hosts
- 进入容器:
- 删除容器:
docker rm [OPTIONS] CONTAINER [CONTAINER...]
- 删除:
docker rm 容器名
- 强制删除:
docker rm -f 容器名
- 删除:
功能详解
- 详细查看https://www.kancloud.cn/woshigrey/docker/935883
attach
Attach local standard input, output, and error streams to a running containercommit
Create a new image from a container’s changescp
Copy files/folders between a container and the local filesystemcreate
Create a new containerdiff
Inspect changes to files or directories on a container’s filesystemevents
Get real time events from the serverexec
Run a command in a running containerexport
Export a container’s filesystem as a tar archiveinspect
Return low-level information on Docker objectskill
Kill one or more running containerslogs
Fetch the logs of a containerpause
Pause all processes within one or more containersport
List port mappings or a specific mapping for the containerps
List containersrename
Rename a containerrestart
Restart one or more containersrm
Remove one or more containersrun
Run a command in a new containerstart
Start one or more stopped containersstats
Display a live stream of container(s) resource usage statisticsstop
Stop one or more running containerstop
Display the running processes of a containerunpause
Unpause all processes within one or more containersupdate
Update configuration of one or more containerswait
Block until one or more containers stop, then print their exit codes
3、管理命令
image
Manage imagesnetwork
Manage networksnode
Manage Swarm nodesservice
Manage servicesstack
Manage Docker stacksswarm
Manage Swarmvolume
Manage volumes