docker笔记

@

狂神docker课程


帮助命令

docker version		显示版本信息
docker info       显示docker系统信息   包括镜像和容器数量
docker --help    帮助命令

镜像命令

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210220121955249.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210220122148903.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

容器命令

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210220122752337.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210220123419347.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
导出容器快照

docker export 1e560fca3906 > ubuntu.tar

导入容器为镜像

cat docker/ubuntu.tar | docker import - test/ubuntu:v1.0

查看容器端口

docker port bf08b7f2cd89
docker port container_name

查看容器标准输出

docker logs -f bf08b7f2cd89

查看容器配置

docker inspect container_name

常用其他命令

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210220124457520.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
在这里插入图片描述
在这里插入图片描述
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210220125229968.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210220125305333.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210220125529926.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210220125612209.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210220125836700.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210220131913217.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210220133848554.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210220135517295.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)

容器数据卷

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210220203526159.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210220203539547.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210220203722785.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210220205934684.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)

安装mysql

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210220211329679.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)

docker run -d --name test_mysql -p 9306:3306 \
-v /home/shiyin/mysql/conf:/etc/mysql/conf.d \
-v /home/shiyin/mysql/data:/var/lib/mysql   \
-e MYSQL_ROOT_PASSWORD=147852zxc mysql 

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210221110301963.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210221110355490.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210221110633994.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210221111902954.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210221112123709.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)

docker build -f  /home/testdocerfile/dockerfile -t centosfile:1.0 .

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210221113254494.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210221120152155.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210221120912367.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210221120847920.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210221120950422.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210221121106245.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)

多个mysql数据同步

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210221121215312.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)

DockerFile

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210221121908172.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210221122012591.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
在这里插入图片描述

指令

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210221122530342.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210221122205562.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)

实战

centos

在这里插入图片描述

FROM centos
MAINTAINER shiyin<123456789@gmail.com>

ENV MYPATH /usr/local
WORKDIR $MYPATH

RUN yum -y install vim
RUN yum -y install net-tools

EXPOSE 80

CMD echo $MYPATH
CMD echo "--end--"
CMD /bin/bash

docker build -f dockerfile -t dockerimagename:1.0 .

tomcat

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210221125156237.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)

![在这里插入图片描述]( https://img-blog.csdnimg.cn/202102211259331.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210221130743157.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
在这里插入图片描述
![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210221131024118.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)

流程

![在这里插入图片描述]( https://img-blog.csdnimg.cn/2021022113112682.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)

网络

  1. docker0相当于路由器

  2. 容器互联

docker run -d --name linux1 --link linux2 linux
docker exec -it linux1 ping linux2  

本质 -- host映射(现在不建议使用)
--link 相当于在host配置文件中添加了一行配置
192.168.1.1 linux2

  1. 自定义网络
查看所有的docker网络
docker network ls

网络模式
bridge 桥接模式
none 不配置网络
host 和宿主机共享网络
container 容器互联网络

创建网络

 docker network create --driver bridge --subnet 192.168.3.0/24 --gateway 192.168.3.1 mynet

--driver 模式 
--subnet  子网 
--gateway 网关

docker run -d -P --name="tomcat1" --net mynet tomcat

docker exec -it tomcat1 ping tomcat2

	PING tomcat2 (192.168.3.3) 56(84) bytes of data.
	64 bytes from tomcat2.mynet (192.168.3.3): icmp_seq=1 ttl=64 time=0.251 ms
	64 bytes from tomcat2.mynet (192.168.3.3): icmp_seq=2 ttl=64 time=0.100 ms
	64 bytes from tomcat2.mynet (192.168.3.3): icmp_seq=3 ttl=64 time=0.054 ms
	64 bytes from tomcat2.mynet (192.168.3.3): icmp_seq=4 ttl=64 time=0.054 ms

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20210504225810367.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzU5Njk0,size_16,color_FFFFFF,t_70)
联通一个容器到一个网络

docker network connect mynet container_name
posted @ 2021-06-08 14:20  剪水行舟  阅读(71)  评论(0)    收藏  举报