上QQ阅读APP看书,第一时间看更新
1.3.2 Docker的使用
对于Docker的使用,可以花整本书来介绍其中的各种细节、使用技巧和实战经验等,本节更希望告诉读者学习使用的方法,而对于使用技巧和实战经验会在本书的其他部分贯穿说明。
对于初学者,官方提供的[tryit](https://www.docker.com/tryit/)是最好的快速入门途径,建议每一个初次接触Docker的用户都可以试一试。对于有一定经验的用户,在使用中遇到问题或者不确定具体的用法时,可以通过以下途径来查看帮助信息。
1)在控制台直接运行docker,这样会列出Docker支持的所有命令和一些通用的参数,如下:
$ docker Usage: docker [OPTIONS] COMMAND [arg...] docker daemon [ --help | ... ] docker [ -h | --help | -v | --version ] A self-sufficient runtime for containers. Options: --config=~/.docker Location of client config files -D, --debug=false Enable debug mode -H, --host=[] Daemon socket(s) to connect to -h, --help=false Print usage -l, --log-level=info Set the logging level --tls=false Use TLS; implied by --tlsverify --tlscacert=~/.docker/ca.pem Trust certs signed only by this CA --tlscert=~/.docker/cert.pem Path to TLS certificate file --tlskey=~/.docker/key.pem Path to TLS key file --tlsverify=false Use TLS and verify the remote -v, --version=false Print version information and quit Commands: attach Attach to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders from a container to a HOSTDIR or to STDOUT create Create a new container diff Inspect changes on a container's filesystem events Get real time events from the server exec Run a command in a running container export Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on a container or image kill Kill a running container load Load an image from a tar archive or STDIN login Register or log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within a container port List port mappings or a specific mapping for the CONTAINER ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart a running container rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save an image(s) to a tar archive search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop a running container tag Tag an image into a repository top Display the running processes of a container unpause Unpause all processes within a container version Show the Docker version information wait Block until a container stops, then print its exit code Run 'docker COMMAND --help' for more information on a command.
2)在控制台执行“docker+命令+--help”,比如“docker start--help”,这样会列出docker start命令支持的所有参数,如下:
$ docker start -–help
Usage: docker start [OPTIONS] CONTAINER [CONTAINER...]
Start one or more stopped containers
-a, --attach=false Attach STDOUT/STDERR and forward signals
--help=false Print usage
-i, --interactive=false Attach container's STDIN
3)使用man命令查看帮助文档。对于通过rpm包等方式安装的Docker,一般都会默认安装对应的man文档,此时可通过“man+docker+command”的方式查看子命令的帮助文档,比如“man docker start”,通常man手册中包含的帮助信息会更丰富一些,通过完整地阅读man手册,基本上就可以掌握该命令的常规用法。
DOCKER(1) JUNE 2014 DOCKER(1) NAME docker-start - Start one or more stopped containers SYNOPSIS docker start [-a|--attach[=false]] [--help] [-i|--interactive[=false]] CONTAINER [CONTAINER...] DESCRIPTION Start one or more stopped containers. OPTIONS -a, --attach=true|false Attach container's STDOUT and STDERR and forward all signals to the process. The default is false. --help Print usage statement -i, --interactive=true|false Attach container's STDIN. The default is false. See also docker-stop(1) to stop a running container. HISTORY April 2014, Originally compiled by William Henry (whenry at redhat dot com) based on docker.com source material and internal work. June 2014, updated by Sven Dowideit (SvenDowideit@home.org.au)