Options: --config string Location of client config files (default "/Users/jaryoung/.docker") -D, --debug Enable debug mode -H, --host list Daemon socket(s) to connect to -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/Users/jaryoung/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/Users/jaryoung/.docker/cert.pem") --tlskey string Path to TLS key file (default "/Users/jaryoung/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit
Commands: attach Attach local standard input, output, and error streams 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 between a container and the local filesystem create Create a new container diff Inspect changes to files or directories 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 Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN login 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 one or more containers 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 one or more containers rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) 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 one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers version Show the Docker version information wait Block until one or more containers stop, then print their exit codes
Run 'docker COMMAND --help' for more information on a command.
docker search
1 2 3 4 5 6 7 8 9 10 11
docker search --help
Usage: docker search [OPTIONS] TERM
Search the Docker Hub for images,为了在Docker Hub上面搜 **资源**(你们都懂得)
Options: -f, --filter filter Filter output based on conditions provided --format string Pretty-print search using a Go template --limit int Max number of search results (default 25) --no-trunc Don't truncate output
例如,我需要搜索一下上面有哪些mysql镜像,我们可以看到下面到信息:
1 2 3 4 5 6
docker search mysql NAME(名称) DESCRIPTION(描述) STARS(多少次好评) OFFICIAL(官方) AUTOMATED(自动化) mysql MySQL is a widely used, open-source relation… 7964 [OK] mariadb MariaDB is a community-developed fork of MyS… 2665 [OK] mysql/mysql-server Optimized MySQL Server Docker images. Create… 598 [OK] ...
docker pull
1 2 3 4 5 6 7 8 9
docker pull --help
Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST]
Pull an image or a repository from a registry
Options: -a, --all-tags Download all tagged images in the repository --disable-content-trust Skip image verification (default true)
例如,我们可以通过 docker pull mysql , 来下载最新版的mysql镜像。如果需要带上TAG,例如 docker pull mysql:5.7
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
Options(删除了一部分,详细的情况,可以自己查询): --add-host list Add a custom host-to-IP mapping (host:ip) -d, --detach Run container in background and print container ID --detach-keys string Override the key sequence for detaching a container --device list Add a host device to the container --device-cgroup-rule list Add a rule to the cgroup allowed devices list --device-read-bps list Limit read rate (bytes per second) from a device (default []) --device-read-iops list Limit read rate (IO per second) from a device (default []) --device-write-bps list Limit write rate (bytes per second) to a device (default []) --device-write-iops list Limit write rate (IO per second) to a device (default []) --disable-content-trust Skip image verification (default true) --dns list Set custom DNS servers --dns-option list Set DNS options --dns-search list Set custom DNS search domains --entrypoint string Overwrite the default ENTRYPOINT of the image -e, --env list Set environment variables --env-file list Read in a file of environment variables --expose list Expose a port or a range of ports --group-add list Add additional groups to join --health-cmd string Command to run to check health --health-interval duration Time between running the check (ms|s|m|h) (default 0s) --health-retries int Consecutive failures needed to report unhealthy --health-start-period duration Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default 0s) --health-timeout duration Maximum time to allow one check to run (ms|s|m|h) (default 0s) --help Print usage -h, --hostname string Container host name --init Run an init inside the container that forwards signals and reaps processes -p, --publish list Publish a container's port(s) to the host -P, --publish-all Publish all exposed ports to random ports --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 --runtime string Runtime to use for this container --security-opt list Security Options --shm-size bytes Size of /dev/shm --sig-proxy Proxy received signals to the process (default true) --stop-signal string Signal to stop a container (default "SIGTERM") --stop-timeout int Timeout (in seconds) to stop a container --storage-opt list Storage driver options for the container --sysctl map Sysctl options (default map[]) --tmpfs list Mount a tmpfs directory -t, --tty Allocate a pseudo-TTY --ulimit ulimit Ulimit options (default []) ... -v, --volume list Bind mount a volume --volume-driver string Optional volume driver for the container --volumes-from list Mount volumes from the specified container(s) -w, --workdir string Working directory inside the container
Mysql
1
docker run -p 3306:3306 --name mysql -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6.43
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 numeric IDs -s, --size Display total file sizes
例如,我们可以运行 docker ps -a ,查询一下我们容器中启动的镜像的情况:
1 2 3 4
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4b9f565ae5ad nginx "nginx -g 'daemon of…" 8 hours ago Up 4 minutes 0.0.0.0:84->80/tcp nginx 46519e512d58 redis "docker-entrypoint.s…" 10 hours ago Up 5 minutes 0.0.0.0:6379->6379/tcp redis 293c9831f58a mysql:5.6.43 "docker-entrypoint.s…" 10 hours ago Up 4 minutes 0.0.0.0:3306->3306/tcp mysql
命令说明:
-a Show all containers (default shows just running),会显示所有存在的,默认是之后显示当前容器启动的镜像。
Options: -d, --detach Detached mode: run command in the background --detach-keys string Override the key sequence for detaching a container -e, --env list Set environment variables -i, --interactive Keep STDIN open even if not attached --privileged Give extended privileges to the command -t, --tty Allocate a pseudo-TTY -u, --user string Username or UID (format: <name|uid>[:<group|gid>]) -w, --workdir string Working directory inside the container