[root@iZ2zeb7ybli3zzdll6airpZ ~]# docker images REPOSITORY TAGIMAGE ID CREATED SIZE nginx latest e784f4560448 4 weeks ago 188MB [root@iZ2zeb7ybli3zzdll6airpZ ~]# docker image ls REPOSITORY TAGIMAGE ID CREATED SIZE nginx latest e784f4560448 4 weeks ago 188MB [root@iZ2zeb7ybli3zzdll6airpZ ~]#
删除:docker rmi 镜像名
1.2 启动容器(container)
运行:docker run
1 2 3 4 5
# 创建并运行一个容器,处于运行状态。(前台运行) docker run nginx # 参数说明 docker run --name [容器名] -p 宿主机端口号:容器内部端口号 -d [镜像名称] docker run -d --name stock_app -p 80:80 nginx
[root@iZ2zeb7ybli3zzdll6airpZ ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d76bb85c0461 nginx "/docker-entrypoint.…" 7 hours ago Up 7 hours 0.0.0.0:80->80/tcp, :::80->80/tcp stock_app [root@iZ2zeb7ybli3zzdll6airpZ ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d76bb85c0461 nginx "/docker-entrypoint.…" 7 hours ago Up 7 hours 0.0.0.0:80->80/tcp, :::80->80/tcp stock_app [root@iZ2zeb7ybli3zzdll6airpZ ~]# docker ps -aq d76bb85c0461 [root@iZ2zeb7ybli3zzdll6airpZ ~]#
停止:docker stop
启动:docker start
重启:docker restart
状态:docker stats
1 2 3 4
[root@iZ2zeb7ybli3zzdll6airpZ ~]# docker stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS d76bb85c0461 stock_app 0.00% 5.285MiB / 3.523GiB 0.15% 28.5MB / 28.6MB 3.47MB / 0B 3
日志:docker logs
进入:docker exec
1 2 3 4
[root@iZ2zeb7ybli3zzdll6airpZ ~]# docker exec -it stock_app /bin/bash root@d76bb85c0461:/# ls bin boot dev docker-entrypoint.d docker-entrypoint.sh etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var root@d76bb85c0461:/#
[root@iZ2zeb7ybli3zzdll6airpZ ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d76bb85c0461 nginx "/docker-entrypoint.…" 7 hours ago Up 7 hours 0.0.0.0:80->80/tcp, :::80->80/tcp stock_app [root@iZ2zeb7ybli3zzdll6airpZ ~]#
Options: -a, --author string Author (e.g., "John Hannibal Smith <hannibal@a-team.com>") -c, --change list Apply Dockerfile instruction to the created image -m, --message string Commit message -p, --pause Pause container during commit (default true) [root@iZ2zeb7ybli3zzdll6airpZ ~]# [root@iZ2zeb7ybli3zzdll6airpZ ~]# docker commit -m "update nginx page" stock_app stock_app:v1.0
保存:docker save
1 2 3 4 5 6 7 8 9 10 11 12 13
[root@iZ2zeb7ybli3zzdll6airpZ ~]# docker save --help
Usage: docker save [OPTIONS] IMAGE [IMAGE...]
Save one or more images to a tar archive (streamed to STDOUT by default)
Aliases: docker image save, docker save
Options: -o, --output string Write to a file, instead of STDOUT [root@iZ2zeb7ybli3zzdll6airpZ ~]# [root@iZ2zeb7ybli3zzdll6airpZ ~]# docker save -o stock_app.tar stock_app:v1.0