Docker——常用命令(四)
来源:互联网 发布:手机上怎样改淘宝评价 编辑:程序博客网 时间:2024/06/09 15:18
本文只列举了几个常用的命令,其他命令可使用--help查看或在网上自行查阅
一、查看当前版本
[root@localhost ~]# docker versionClient version: 1.7.1Client API version: 1.19Go version (client): go1.4.2Git commit (client): 786b29d/1.7.1OS/Arch (client): linux/amd64Server version: 1.7.1Server API version: 1.19Go version (server): go1.4.2Git commit (server): 786b29d/1.7.1OS/Arch (server): linux/amd64[root@localhost ~]# docker -vDocker version 1.7.1, build 786b29d/1.7.1[root@localhost ~]#
二、查看当前所有docker镜像
[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE[root@localhost ~]#
三、拉取远程docker镜像
网易蜂巢docker镜像库地址:https://c.163.com/hub#/m/home/
命令:docker pull [OPTIONS] NAME[:TAG]
e.g.. docker pull hub.c.163.com/wangjiaen/centos6.9:ssh (从网易蜂巢拉取一个contos6.9的镜像)
[root@localhost ~]# docker pull hub.c.163.com/wangjiaen/centos6.9:sshssh: Pulling from hub.c.163.com/wangjiaen/centos6.9ebe688773310: Pull complete 7d9a6cbcf4ff: Pull complete 48a89683e055: Pull complete 166c7265ea0d: Pull complete 5caf8ed79df7: Already exists Digest: sha256:0d07d3e54a974c483c83dd64194718968b962e74c805833633fd12a5d0f31774Status: Downloaded newer image for hub.c.163.com/wangjiaen/centos6.9:ssh[root@localhost ~]#
四、Docker的帮助命令
命令:docker COMMAND --help
e.g.. docker --help 、 docker run --help (列出docker的参数命令帮助、列出docker run的参数命令帮助)
[root@localhost ~]# docker run --helpUsage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]Run a command in a new container -a, --attach=[] Attach to STDIN, STDOUT or STDERR --add-host=[] Add a custom host-to-IP mapping (host:ip) --blkio-weight=0 Block IO (relative weight), between 10 and 1000 -c, --cpu-shares=0 CPU shares (relative weight) --cap-add=[] Add Linux capabilities --cap-drop=[] Drop Linux capabilities --cgroup-parent= Optional parent cgroup for the container --cidfile= Write the container ID to the file --cpu-period=0 Limit CPU CFS (Completely Fair Scheduler) period --cpu-quota=0 Limit the CPU CFS quota --cpuset-cpus= CPUs in which to allow execution (0-3, 0,1) --cpuset-mems= MEMs in which to allow execution (0-3, 0,1) -d, --detach=false Run container in background and print container ID --device=[] Add a host device to the container --dns=[] Set custom DNS servers --dns-search=[] Set custom DNS search domains -e, --env=[] Set environment variables --entrypoint= Overwrite the default ENTRYPOINT of the image --env-file=[] Read in a file of environment variables --expose=[] Expose a port or a range of ports -h, --hostname= Container host name --help=false Print usage -i, --interactive=false Keep STDIN open even if not attached --ipc= IPC namespace to use -l, --label=[] Set meta data on a container --label-file=[] Read in a line delimited file of labels --link=[] Add link to another container --log-driver= Logging driver for container --log-opt=[] Log driver options --lxc-conf=[] Add custom lxc options -m, --memory= Memory limit --mac-address= Container MAC address (e.g. 92:d0:c6:0a:29:33) --memory-swap= Total memory (memory + swap), '-1' to disable swap --name= Assign a name to the container --net=bridge Set the Network mode for the container --oom-kill-disable=false Disable OOM Killer -P, --publish-all=false Publish all exposed ports to random ports -p, --publish=[] Publish a container's port(s) to the host --pid= PID namespace to use --privileged=false Give extended privileges to this container --read-only=false Mount the container's root filesystem as read only --restart=no Restart policy to apply when a container exits --rm=false Automatically remove the container when it exits --security-opt=[] Security Options --sig-proxy=true Proxy received signals to the process -t, --tty=false Allocate a pseudo-TTY -u, --user= Username or UID (format: <name|uid>[:<group|gid>]) --ulimit=[] Ulimit options --uts= UTS namespace to use -v, --volume=[] Bind mount a volume --volumes-from=[] Mount volumes from the specified container(s) -w, --workdir= Working directory inside the container[root@localhost ~]#
五、运行docker镜像
命令:docker run [OPTIONS] images[:TAG]
e.g.. docker run -d 5caf8ed (在后台运行ID为5caf8ed的镜像,注:-d为参数,指后台运行且打印运行容器ID,5caf8ed为镜像的ID前端部分,ID不一定要输全,只要能够区分开docker就知道要运行哪个)
[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEhub.c.163.com/wangjiaen/centos6.9 ssh 5caf8ed79df7 9 weeks ago 370.9 MB[root@localhost ~]# docker run -d 5caf8ed28d26a28befb16feb8506df458871a8416f1e9ae02e253d363fa4bba38180e6a[root@localhost ~]#
六、查看正在运行的容器
命令:docker ps
docker ps -a 列出所有容器
docker ps -l 最后创建的容器
其他参数不明白可以输入:docker ps --help自行查看(其他命令一样,不懂就--help,以后就不赘述了)
[root@localhost ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES28d26a28befb 5caf8ed "/usr/sbin/sshd -D" 4 hours ago Up 4 hours 22/tcp cranky_wright [root@localhost ~]#
七、进入容器内部
命令:docker exec [OPTIONS] CONTAINER COMMAND [ARG...]e.g.. docker exec -i -t IMAGE /bin/bash
e.g.. docker exec -it 28d bash (-it即-i -t ,以交互模式进入容器ID为:28d*的容器内部,bash即执行/bin/bash脚本,如示例已经进入centos6.9内部)
[root@localhost ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES28d26a28befb 5caf8ed "/usr/sbin/sshd -D" 4 hours ago Up 4 hours 22/tcp cranky_wright [root@localhost ~]# docker exec -it 28d bash[root@28d26a28befb /]# lsbin boot devetc home liblib64 media mnt optproc root sbin selinux srvsys tmp usr var[root@28d26a28befb /]#
八、退出容器
命令:exit
[root@28d26a28befb /]# lsbin boot devetc home liblib64 media mnt optproc root sbin selinux srvsys tmp usr var[root@28d26a28befb /]# exitexit[root@localhost ~]#
九、停止正在运行的容器
命令:docker stop ContainerID
e.g.. docker stop 28d26a28befb (停止正在运行的ID为28d26a28befb的容器)
[root@localhost ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES28d26a28befb 5caf8ed "/usr/sbin/sshd -D" 4 hours ago Up 4 hours 22/tcp cranky_wright [root@localhost ~]# docker stop 28d26a28befb28d26a28befb[root@localhost ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES[root@localhost ~]#
内链:
Docker——YUM升级centOS内核(一)
Docker——安装部署(二)
Docker——版本升级(三)
Docker——常用命令(四)
Docker——第一个docker服务tomcat(五)
Docker——给tomcat容器部署项目并且做成新的镜像(容器内外拷贝)(六)
- Docker——常用命令(四)
- Docker-常用命令(四)
- Docker学习总结(9)——Docker常用命令
- Docker 网络(四)——Docker 容器网络
- Docker小技巧(七)——常用命令
- Docker入门实战(一)——Docker常用命令
- docker常用命令(总结)
- docker常用命令(三)
- (三)Docker常用命令
- Docker学习笔记(2)-- Docker常用命令
- 08 - Docker常用命令(Docker系列)
- Docker数据管理(四)
- Docker 入门教程(四)
- Docker笔记(1)--常用命令
- Docker笔记(1)--常用命令
- docker 常用命令(持续更新)
- Docker系列~常用命令(二)
- docker常用命令(持续补充)
- word2vec
- 使用Java读取Excel文件内容
- 深入理解javascript原型和闭包(13)-【作用域】和【上下文环境】
- 软件开发流程回顾
- Unity3d MVCS游戏框架Robotlegs
- Docker——常用命令(四)
- java集合系列01--ArrayList
- Android APP测试的日志文件抓取
- CJOJ 1070 【Uva】嵌套矩形
- leetcode 122. Best Time to Buy and Sell Stock II
- scala基础系列一
- 递归与分治策略之大整数的乘法
- 深入理解javascript原型和闭包(14)——从【自由变量】到【作用域链】
- [莫比乌斯反演+容斥+分块求和] BZOJ2301: [HAOI2011]Problem b