命令:docker ps [options]linux
options有:docker
-a:查看全部容器,包含不在运行中的(不带-a参数,是只显示运行中的容器)bash
-q:只显示容器ID服务器
-s:多加一列来显示总文件大小网络
-l:显示最近建立的容器(docker ps -l)app
-n:显示最近建立的n个容器(docker ps -n 3, 显示最近建立的3个容器)ui
--filter:根据条件过滤(不经常使用,容器数量没大到那种程度须要用过滤器才能找到。)spa
docker run [options] 镜像名或镜像ID [command] [agrs]rest
数据卷是一种技术,而不是某一个东西。日志
简单理解就是,将本机的某一个目录映射到某一个或者多个容器的某目录。这样在本机修改代码,就能够直接用容器跑代码
数据卷 是一个可供一个或者多个容器使用的特殊目录,它绕过UFS,能够提供不少有用的特性:
注意:数据卷 的使用,相似linux下对目录或者文件进行mount,镜像中的被指定为挂载点的目录中的文件会隐藏掉,能显示看的是挂着的 数据卷。
在用镜像来建立一个容器的同时,指定“-v”参数来指定目录映射
准备:受权本地磁盘
命令:docker run -v 本地目录:容器目录 镜像名称或镜像ID
若是要同时挂载多个目录,能够执行多个 -v 便可,如:
docker run -v 本地目录1:容器目录1 -v 本地目录2:容器目录2 镜像名称或镜像ID
命令:docker start 容器ID或容器名
一个容器已经经过镜像建立成功了,可是当初建立的时候,因为考虑不周,忘了一些参数(好比开机启动),这时候能够经过 update 命令来更新容器。
命令:docker update [options] 容器名或容器ID
--blkio-weight(uint16): Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
--cpu-period(int): Limit CPU CFS (Completely Fair Scheduler) period
--cpu-quota(int): Limit CPU CFS (Completely Fair Scheduler) quota
--cpu-rt-period(int): Limit the CPU real-time period in microseconds
--cpu-rt-runtime(int): Limit the CPU real-time runtime in microseconds
--cpu-shares(int): CPU shares (relative weight)
--cpus(decimal): Number of CPUs
--cpuset-cpus(string): CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems(string): MEMs in which to allow execution (0-3, 0,1)
--kernel-memory(bytes): Kernel memory limit
--memory bytes Memory limit
--memory-reservation(bytes): Memory soft limit
--memory-swap(bytes): Swap limit equal to memory plus swap: '-1' to enable unlimited swap
--restart(string): Restart policy to apply when a container exits
命令:docker stop [options] 容器名或者容器ID
options有:
-t:杀死容器进程前,给予容器用来中止的时间(默认是10秒)
命令:docker restart [options] 容器名或容器ID
options有:
-t:杀死容器进程前,给予容器用来中止的时间(默认是10秒)
即便容器是关闭状态,也能够重启,这点不像supervisor,supervisor的进程是关闭状态的话,则没法restart,只能start
命令:docker rm [options] 容器名或容器ID
options有:
-f:强制删除容器(默认状况下,只有是中止状态的容器才能够删除,可是带上-f后,能够直接删除在运行中的容器)
-l:移除容器间的网络连接,而非容器自己(不懂,好像也用的少)
-v:删除与容器关联的卷(这个仍是能够有的)
命令:docker rm -f $(docker ps -a -q)
不是什么新的知识点
命令:docker exec [options] 容器名或容器ID [command]
通常是:docker exec -it 容器名或容器ID /bin/bash ,用于进入容器,是否真的能在外面作到其余的操做,暂未可知,我是验证了:docker exec 容器名 echo "hello world">test.txt ,未成功
命令:docker logs 容器名或容器ID
命令:docker cp 主机文件 容器ID或容器名:容器目录
有点相似本机与远程服务器之间的内容拷贝:scp 本机文件 远程服务器:目录
命令:docker cp 容器ID或容器名:目录/文件 本机目录