docker使用这里写自定义目录标题)
docker批量操作
docker怎么批量启动
批量启动docker镜像
[root@centos7_01 docker]# for i in `docker images |awk '{print $3}' |sed -n '1!p'`;
> do
> docker run -itd $i bash;
> done;
e0d9dc728f086960157cdde227f65384dffefc5677f1bc6d84edf2ef582363ac
d90e4189fdfcb7cac3289d1dba9d4dfae037ff46a57db9938ade0e1c48bdf3a9
acd55ee4ab07564f9ee85fd70f0a1c8febbc4e68b7b748cf86437a492d4f1a10
c5b296cbd47f288669ab7276d9391ba2713190e4ae140dec629d5c13df3d842b
4bb74d59db77c126891284bbd13aa4c97e346dc9ce6bfa85782b3bc6d741850b
[root@centos7_01 docker]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4bb74d59db77 0f3e07c0138f "bash" 12 seconds ago Up 11 seconds upbeat_moser
c5b296cbd47f 0f3e07c0138f "bash" 13 seconds ago Up 12 seconds amazing_spence
acd55ee4ab07 0f3e07c0138f "bash" 13 seconds ago Up 13 seconds fervent_lamport
d90e4189fdfc 32b224295d5a "bash" 14 seconds ago Up 13 seconds optimistic_tharp
e0d9dc728f08 1c5d371dbac3 "bash" 15 seconds ago Up 14 seconds wizardly_bartik
[root@centos7_01 docker]#
docker images查看docker中镜像,awk ‘{print $3}'把第3列打印出来
sed -n '1!p’把除了第一行的"IMAGE ID"给删掉只保留镜像id
docker怎么批量停止所有启动的容器?
使用:
关闭所有包括关闭过的容器
docker stop $(docker ps -a -q)
关闭Up和Created状态的容器
docker stop $(docker ps -a |grep -E '(Up|Created)'|awk '{print $1}'
关闭Up状态的容器
docker stop $(docker ps -a | grep Up | awk '{print $1}'
如下图: