Hello from Docker! This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/
For more examples and ideas, visit: https://docs.docker.com/get-started/
Options: --config string Location of client config files (default"/root/.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"/root/.docker/ca.pem") --tlscert string Path to TLS certificate file (default"/root/.docker/cert.pem") --tlskey string Path to TLS key file (default"/root/.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.
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
[root@caoxl ~]# docker run -d -P training/webapp python app.py fc14b64cda1d2445bcea207ece36b9b274f3a422be26c92bd95cbe1af96d0d6e
参数说明
-d: 让容器在后台运行
-P: 将容器内部使用的网络端口映射到我们使用的手机上
查看WEB应用容器
1 2 3 4
[root@caoxl ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fc14b64cda1d training/webapp "python app.py" About a minute ago Up About a minute 0.0.0.0:32768->5000/tcp hopeful_mendel c4d4afebb0d1 pinguo/php-msf-demo:newdev "/run.sh /usr/sbin/s…"27 minutes ago Up 27 minutes 0.0.0.0:443->443/tcp, 80/tcp, 0.0.0.0:8000->8000/tcp, 0.0.0.0:2202->22/tcp pinguo_php-msf-demo_newdev
[root@caoxl ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest fce289e99eb9 4 months ago 1.84kB pinguo/php-msf-demo newdev 39995bac5087 18 months ago 1.54GB registry.cn-hangzhou.aliyuncs.com/pinguo-ops/php-msf-docker latest 39995bac5087 18 months ago 1.54GB training/webapp latest 6fae60ef3446 4 years ago 349MB
[root@caoxl ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1e13c99fa213 nginx "nginx -g 'daemon of…"17 seconds ago Up 16 seconds 0.0.0.0:8081->80/tcp caoxl
# ps 列出运行的容器列表 [root@caoxl ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES # ps -a 列出所有容器列表 [root@caoxl ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@caoxl ~]# docker search mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, open-source relation… 8142 [OK] mariadb MariaDB is a community-developed fork of MyS… 2771 [OK]
[root@caoxl ~]# docker images | grep mysql mysql 5.77faa3c53e6d6 7 days ago 373MB
Docker 安装Redis
1 2 3 4 5
[root@caoxl ~]# docker search redis NAME DESCRIPTION STARS OFFICIAL AUTOMATED redis Redis is an open source key-value store that… 6900 [OK] bitnami/redis Bitnami Redis Docker Image 112 [OK]
# 删除一个或多个容器(需先停止容器) [root@caoxl ~]# docker rm ade302349866 Error response from daemon: You cannot remove a running container ade30234986633c113e9b1e5828d6e6e1f8f74c47cdb878674cec1a2e4a7db3d. Stop the container before attempting removal or force remove
[root@caoxl ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9bf46c51c287 nginx "nginx -g 'daemon of…"34 minutes ago Up 34 minutes 0.0.0.0:8081->80/tcp caoxl-nginx
[root@caoxl ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9bf46c51c287 nginx "nginx -g 'daemon of…"36 minutes ago Up 36minutes (Paused) 0.0.0.0:8081->80/tcp caoxl-nginx
[root@caoxl ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE redis 5.0 a4fe14ff1981 7 days ago 95MB php 7.2-fpm 0be748e55df6 7 days ago 366MB nginx latest 53f3fd8007f7 7 days ago 109MB mysql 5.77faa3c53e6d6 7 days ago 373MB
[root@caoxl ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9bf46c51c287 nginx "nginx -g 'daemon of…"39 minutes ago Up 39 minutes 0.0.0.0:8081->80/tcp caoxl-nginx
[root@caoxl ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2af5be371c15 mysql:5.7"docker-entrypoint.s…"10 seconds ago Created caoxl-mysql 2b077bf72f07 nginx:latest "nginx -g 'daemon of…"13 minutes ago Exited (137) 7 minutes ago nginx 9bf46c51c287 nginx "nginx -g 'daemon of…"39 minutes ago Up 39 minutes 0.0.0.0:8081->80/tcp caoxl-nginx
exec - 在运行中的容器中执行命令
1 2 3 4
# 在运行中的容器中执行命令 [root@caoxl ~]# docker exec -i -t nginx /bin/bash root@2b077bf72f07:/# ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
容器操作
ps - 列出容器
1 2 3 4
[root@caoxl ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2b077bf72f07 nginx:latest "nginx -g 'daemon of…"18 minutes ago Up 2 minutes 80/tcp nginx 9bf46c51c287 nginx "nginx -g 'daemon of…"44 minutes ago Up 43 minutes 0.0.0.0:8081->80/tcp caoxl-nginx
# 登陆 [root@caoxl ~]# docker login -u username -p password WARNING! Using --password via the CLI is insecure. Use --password-stdin. WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store
[root@caoxl ~]# docker push php:7.2-fpm The push refers to repository [docker.io/library/php]
search - 从Docker Hub查找镜像
1 2 3 4 5 6
root@caoxl ~]# docker search swoole NAME DESCRIPTION STARS OFFICIAL AUTOMATED xlight/docker-php7-swoole php7-cli with swoole 28 [OK] twosee/swoole-coroutine Perfect Swoole Dockerfile for senior develop… 27 [OK] kong36088/nginx-php7-swoole nginx+php7+swoole拓展,另外自带redis和memcac… 14 ...
本地镜像管理
images - 列出本地镜像
1 2 3 4 5 6 7
[root@caoxl ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE redis 5.0 a4fe14ff1981 7 days ago 95MB php 7.2-fpm 0be748e55df6 7 days ago 366MB nginx latest 53f3fd8007f7 7 days ago 109MB mysql 5.77faa3c53e6d6 7 days ago 373MB swoft/swoft latest 493b8cc21299 3 months ago 447MB
[root@caoxl ~]# docker tag swoft/swoft:latest swoft/swoft:swoft [root@caoxl ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE swoft/swoft latest 493b8cc21299 3 months ago 447MB swoft/swoft swoft 493b8cc21299 3 months ago 447MB
history - 查看指定镜像的创建历史
1 2 3 4 5 6 7 8 9 10 11 12 13
# 查看本地镜像nginx的创建历史 [root@caoxl ~]# docker history nginx IMAGE CREATED CREATED BY SIZE COMMENT 53f3fd8007f7 7 days ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon… 0B <missing> 7 days ago /bin/sh -c #(nop) STOPSIGNAL SIGTERM 0B <missing> 7 days ago /bin/sh -c #(nop) EXPOSE 80 0B <missing> 7 days ago /bin/sh -c ln -sf /dev/stdout /var/log/nginx… 22B <missing> 7 days ago /bin/sh -c set -x && apt-get update && apt… 54.1MB <missing> 7 days ago /bin/sh -c #(nop) ENV NJS_VERSION=1.15.12.0… 0B <missing> 7 days ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.15.12… 0B <missing> 7 days ago /bin/sh -c #(nop) LABEL maintainer=NGINX Do… 0B <missing> 7 days ago /bin/sh -c #(nop) CMD ["bash"] 0B <missing> 7 days ago /bin/sh -c #(nop) ADD file:fcb9328ea4c115670… 55.3MB
[root@caoxl ~]# docker version Client: Version: 18.09.6 API version: 1.39 Go version: go1.10.8 Git commit: 481bc77156 Built: Sat May 402:34:582019 OS/Arch: linux/amd64 Experimental: false
Server: Docker Engine - Community Engine: Version: 18.09.6 API version: 1.39 (minimum version 1.12) Go version: go1.10.8 Git commit: 481bc77 Built: Sat May 402:02:432019 OS/Arch: linux/amd64 Experimental: false
常见问题
image is referenced in multiple repositories
查看镜像
1 2 3 4 5 6 7
[root@caoxl ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE php 7.2-fpm 0be748e55df6 7 days ago 366MB nginx latest 53f3fd8007f7 7 days ago 109MB mysql 5.77faa3c53e6d6 7 days ago 373MB pinguo/php-msf-demo newdev 39995bac5087 18 months ago 1.54GB registry.cn-hangzhou.aliyuncs.com/pinguo-ops/php-msf-docker latest 39995bac5087 18 months ago 1.54GB
删除镜像
1 2
[root@caoxl ~]# docker rmi 39995bac5087 Error response from daemon: conflict: unable to delete 39995bac5087 (must be forced) - image is referenced in multiple repositories
[root@caoxl ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE php 7.2-fpm 0be748e55df6 7 days ago 366MB nginx latest 53f3fd8007f7 7 days ago 109MB mysql 5.77faa3c53e6d6 7 days ago 373MB