docker安装及使用-tag标签

1.docker安装设置启动

yum -y install docker
systemctl start docker
systemctl enable docker

docker search centos
docker pull docker.io/centos
docker images
 

2.docker加速 

 

vi  /etc/docker/daemon.json   

改: {}

为:

{

"registry-mirrors": ["https://e9yneuy4.mirror.aliyuncs.com"]

}

 systemctl daemon-reload

systemctl restart docker

 docker pull docker.io/centos  

3.导入景象

docker load -i  /root/docker.io-centos-lastest-image.tar

  站点下载  

  docker pull hub.c.163.com/library/tomcat:latest

开启转发功能不然会报错

vim /etc/sysctl.conf  #插入以下内容

net.ipv4.ip_forward = 1

[root@xuegod63 ~]# sysctl  -p   #生效

net.ipv4.ip_forward = 1

docker ps

docker stop 1a63ddea6571  关闭容器

docker start 1a63ddea6571

docker restart 1a63ddea6571

docker rm  e085da6919af

4.docker镜像制作方法

docker commit bbd01c4b8567 docker.io/centos:apache

docker build -t docker.io/centos:httpd ./  #后面是脚本文件

5.导出

docker save -o docker.io-centos-httpd-image.tar docker.io/centos:httpd

 6.端口转发

[root@xuegod63 ~]# systemctl start firewalld ; systemctl enable firewalld

[root@xuegod63 ~]# iptables -F  #一定要清空一下规则

启动 container

 docker run -d -p 80:80  docker.io/centos:httpd

进入容器

docker exec -it 87fadc0249a9 /bin/bash

echo xuegod > /var/www/html/test.html

curl http://192.168.1.63/test.html

[root@a9c3a7bf2054 /]# yum install net-tools -y

[root@a9c3a7bf2054 /]# ifconfig 

echo 123456 | passwd --stdin root

 docker run -it --name docker3 -h docker63.cn centos  bash #指定主机名的docker

docker run -itd --name docker10 --cpuset-cpus 0,1 --cpu-shares 512 centos /bin/bash  #cpu控制

docker run -it --rm --name mk centos sleep 5  #延迟5秒执行

 docker run -it  -m 128m centos #内存控制

docker run  -it --name web1 -v /var/www/html/:/var/www/html centos bash

touch /var/www/html/index.html

docker run -it  -v /var/www/html/:/var/www/html --device /dev/sda:/dev/sda --device-write-bps /dev/sda:1mb centos  /bin/bash # io控制

time dd if=/dev/sda of=/var/www/html/test.out bs=1M count=50 oflag=direct,nonblock

注:dd 参数:

direct:读写数据采用直接IO方式; nonblock:读写数据采用非阻塞IO方式

 docker run -it --privileged centos:latest bash #特权模式

 

 docker inspect  容器实例 ID #查看容器的详细情况

7.删除拉取到的镜像

docker rmi 192.168.1.63:5000/busybox 

8.docker拷贝文件护拷

 docker cp RS-MapReduce 30026605dcfe:/home/cloudera

 docker cp 30026605dcfe:/home/cloudera/RS-MapReduce /tmp/

9.日志查看

docker logs zabbix_server

 

 

 

在容器执行

yum install httpd -y
systemctl start httpd

/usr/sbin/httpd -DFOREGROUND &

netstat -antup | grep 80
echo aaaaa > index.html 

docker run -itd -p 80:80 -m 500m -h zsl.cn -v /var/www/html/:/var/www/html --device /dev/sda:/dev/sda --device-write-bps /dev/sda:1mb --name docker10 --cpuset-cpus 0,1,3 --cpu-shares 512 centos /bin/bash

 

 

批量管理docker

docker中 启动所有的容器命令

docker start $(docker ps -a | awk '{ print $1}' | tail -n +2)
docker中 关闭所有的容器命令

docker stop $(docker ps -a | awk '{ print $1}' | tail -n +2)
docker中 删除所有的容器命令

docker rm $(docker ps -a | awk '{ print $1}' | tail -n +2)
docker中 删除所有的镜像

docker rmi $(docker images | awk '{print $3}' |tail -n +2)
tail -n +2 表示从第二行开始读取
批量打包

docker save $(docker images | grep -v REPOSITORY | awk 'BEGIN{OFS=":";ORS=" "}{print $1,$2}') -o haha.tar #全部打包

docker load -i haha.tar

docker save $(docker images | grep -v REPOSITORY | sed -n '1,2p' | awk 'BEGIN{OFS=":";ORS=" "}{print $1,$2}') -o haha1.tar#自定义行打包


docker images|grep none|awk '{print $3 }'|xargs docker rmi #删除关键字的包

docker rm $(docker ps -a | grep Exited | awk '{ print $1}' | tail -n +2) #清除退出的容器

 

 docker tag标签

docker pull nginx:latest
docker tag nginx:latest 192.168.130.84:5000/nginx:latest
docker push 192.168.130.84:5000/nginx:latest

 

docker应用参考

https://www.cnblogs.com/elvi/p/8463812.html

posted @ 2018-10-18 14:28  夜辰雪扬  阅读(1504)  评论(0)    收藏  举报