- 尚硅谷大数据技术-教程-学习路线-笔记汇总表【课程资料下载】
- 视频地址:尚硅谷Docker实战教程(docker教程天花板)_哔哩哔哩_bilibili
- 尚硅谷Docker实战教程-笔记01【基础篇,Docker理念简介、官网介绍、平台入门图解、平台架构图解】
- 尚硅谷Docker实战教程-笔记02【基础篇,Docker安装、镜像加速器配置】
- 尚硅谷Docker实战教程-笔记03【基础篇,Docker常用命令】
- 尚硅谷Docker实战教程-笔记04【基础篇,Docker镜像】
尚硅谷Docker实战教程-笔记05【基础篇,Docker本地镜像发布到阿里云与私有库】
尚硅谷Docker实战教程-笔记06【基础篇,Docker容器数据卷】
尚硅谷Docker实战教程-笔记07【基础篇,Docker常规安装简介】
尚硅谷Docker实战教程-笔记08【高级篇,Docker复杂安装详说】
尚硅谷Docker实战教程-笔记09【高级篇,DockerFile解析】
尚硅谷Docker实战教程-笔记10【高级篇,Docker微服务实战】
尚硅谷Docker实战教程-笔记11【高级篇,Docker网络】
尚硅谷Docker实战教程-笔记12【高级篇,Docker-compose容器编排】
尚硅谷Docker实战教程-笔记13【高级篇,Docker轻量级可视化工具Portainer】
尚硅谷Docker实战教程-笔记14【高级篇,Docker容器监控之CAdvisor+InfluxDB+Granfana、Docker终章总结】
尚硅谷Docker实战教程-笔记15【高级篇,Docker终章总结】
目录
2.高级篇(大厂进阶)
2.DockerFile解析
P057【57_Dockerfile简介】07:48
P058【58_DockerFile构建过程解析】06:10
P059【59_Dockerfile保留字简介】24:40
P060【60_centos之dockerfile需求说明】05:26
P061【61_centos之dockerfile案例演示】11:03
P062【62_虚悬镜像】07:47
2.高级篇(大厂进阶)
2.DockerFile解析
P057【57_Dockerfile简介】07:48
官网:Dockerfile reference | Docker Documentation
P058【58_DockerFile构建过程解析】06:10
从应用软件的角度来看,Dockerfile、Docker镜像与Docker容器分别代表软件的三个不同阶段,
- * Dockerfile是软件的原材料;
- * Docker镜像是软件的交付品;
- * Docker容器则可以认为是软件镜像的运行态,也即依照镜像运行的容器实例。
Dockerfile面向开发,Docker镜像成为交付标准,Docker容器则涉及部署与运维,三者缺一不可,合力充当Docker体系的基石。
Dockerfile,需要定义一个Dockerfile,Dockerfile定义了进程需要的一切东西。Dockerfile涉及的内容包括执行代码或者是文件、环境变量、依赖包、运行时环境、动态链接库、操作系统的发行版、服务进程和内核进程(当应用进程需要和系统服务和内核进程打交道,这时需要考虑如何设计namespace的权限控制)等等;
Docker镜像,在用Dockerfile定义一个文件之后,docker build时会产生一个Docker镜像,当运行 Docker镜像时会真正开始提供服务;
Docker容器,容器是直接提供服务的。
P059【59_Dockerfile保留字简介】24:40
Tomcat镜像-GitHub:https://github.com/docker-library/tomcat/blob/16a2137a26ae88227d8bac176182235ad69c82b3/11.0/jdk21/openjdk-bookworm/Dockerfile
#
# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh"
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#
FROM openjdk:21-jdk-bookworm
ENV CATALINA_HOME /usr/local/tomcat
ENV PATH $CATALINA_HOME/bin:$PATH
RUN mkdir -p "$CATALINA_HOME"
WORKDIR $CATALINA_HOME
# let "Tomcat Native" live somewhere isolated
ENV TOMCAT_NATIVE_LIBDIR $CATALINA_HOME/native-jni-lib
ENV LD_LIBRARY_PATH ${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$TOMCAT_NATIVE_LIBDIR
# see https://www.apache.org/dist/tomcat/tomcat-11/KEYS
# see also "versions.sh" (https://github.com/docker-library/tomcat/blob/master/versions.sh)
ENV GPG_KEYS A9C5DF4D22E99998D9875A5110C01C5A2F6059E7
Last login: Thu Jul 6 09:35:29 2023 from 192.168.10.1
[root@node001 ~]# docker run -it ubuntu /bin/bash
root@905b3a8333e6:/# pwd
/
root@905b3a8333e6:/# exit
exit
[root@node001 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
node001:5000/vluubuntu 1.2 a1ed6fe2f61e 6 days ago 118MB
vluubuntu 1.2 a1ed6fe2f61e 6 days ago 118MB
ubuntu 1.2 7295d0d3bc7e 6 days ago 118MB
registry.cn-hangzhou.aliyuncs.com/vlu001/myubuntu 1.3 079bf1275a8a 6 days ago 185MB
atguigu/ubuntu 3.7 7b40f602c178 7 days ago 72.8MB
hello-world <none> 9c7a54a9a43c 2 months ago 13.3kB
tomcat latest fb5657adc892 18 months ago 680MB
mysql 5.7 c20987f18b13 18 months ago 448MB
registry latest b8604a3fe854 20 months ago 26.2MB
ubuntu latest ba6acccedd29 20 months ago 72.8MB
hello-world latest feb5d9fea6a5 21 months ago 13.3kB
redis 6.0.8 16ecd2772934 2 years ago 104MB
billygoo/tomcat8-jdk8 latest 30ef4019761d 4 years ago 523MB
[root@node001 ~]# docker run -it -p 8080:8080 30ef4019761d bash
root@a73f91c73851:/usr/local/tomcat# pwd
/usr/local/tomcat
root@a73f91c73851:/usr/local/tomcat# exit
exit
[root@node001 ~]# docker run -it -p 8080:8080 30ef4019761d
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
P060【60_centos之dockerfile需求说明】05:26
[root@node001 ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
a1d0c7532777: Pull complete
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
[root@node001 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
vluubuntu 1.2 a1ed6fe2f61e 6 days ago 118MB
node001:5000/vluubuntu 1.2 a1ed6fe2f61e 6 days ago 118MB
ubuntu 1.2 7295d0d3bc7e 6 days ago 118MB
registry.cn-hangzhou.aliyuncs.com/vlu001/myubuntu 1.3 079bf1275a8a 7 days ago 185MB
atguigu/ubuntu 3.7 7b40f602c178 7 days ago 72.8MB
hello-world <none> 9c7a54a9a43c 2 months ago 13.3kB
tomcat latest fb5657adc892 18 months ago 680MB
mysql 5.7 c20987f18b13 18 months ago 448MB
registry latest b8604a3fe854 20 months ago 26.2MB
ubuntu latest ba6acccedd29 20 months ago 72.8MB
hello-world latest feb5d9fea6a5 21 months ago 13.3kB
centos latest 5d0da3dc9764 21 months ago 231MB
redis 6.0.8 16ecd2772934 2 years ago 104MB
billygoo/tomcat8-jdk8 latest 30ef4019761d 4 years ago 523MB
[root@node001 ~]# docker run -it 5d0da3dc9764 /bin/bash
[root@365542d50727 /]# exit
exit
[root@node001 ~]# docker images centos
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 5d0da3dc9764 21 months ago 231MB
[root@node001 ~]#
P061【61_centos之dockerfile案例演示】11:03
下载linux-jdk:小柒博客 | 开源软件镜像站
jdk-8u171-linux-x64.tar.gz 182.0 MiB 2022-Sep-07 15:18
FROM centos:7
MAINTAINER zzyy<zzyybs@126.com>
ENV MYPATH /usr/local
WORKDIR $MYPATH
#安装vim编辑器
RUN yum -y install vim
#安装ifconfig命令查看网络IP
RUN yum -y install net-tools
#安装java8及lib库
RUN yum -y install glibc.i686
RUN mkdir /usr/local/java
#ADD 是相对路径jar,把jdk-8u171-linux-x64.tar.gz添加到容器中,安装包必须要和Dockerfile文件在同一位置
ADD jdk-8u171-linux-x64.tar.gz /usr/local/java/
#配置java环境变量
ENV JAVA_HOME /usr/local/java/jdk1.8.0_171
ENV JRE_HOME $JAVA_HOME/jre
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
ENV PATH $JAVA_HOME/bin:$PATH
EXPOSE 80
CMD echo $MYPATH
CMD echo "success--------------ok"
CMD /bin/bash
[root@node001 jdk]# docker build -t centosjava8:1.5 .
[+] Building 112.3s (12/12) FINISHED
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 782B 0.0s
=> [internal] load metadata for docker.io/library/centos:7 16.1s
=> [1/7] FROM docker.io/library/centos:7@sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987 25.5s
=> => resolve docker.io/library/centos:7@sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987 0.0s
=> => sha256:2d473b07cdd5f0912cd6f1a703352c82b512407db6b05b43f2553732b55df3bc 76.10MB / 76.10MB 7.9s
=> => sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987 1.20kB / 1.20kB 0.0s
=> => sha256:dead07b4d8ed7e29e98de0f4504d87e8880d4347859d839686a31da35a3b532f 529B / 529B 0.0s
=> => sha256:eeb6ee3f44bd0b5103bb561b4c16bcb82328cfe5809ab675bb17ab3a16c517c9 2.75kB / 2.75kB 0.0s
=> => extracting sha256:2d473b07cdd5f0912cd6f1a703352c82b512407db6b05b43f2553732b55df3bc 17.2s
=> [internal] load build context 3.3s
=> => transferring context: 190.93MB 3.3s
=> [2/7] WORKDIR /usr/local 0.0s
=> [3/7] RUN yum -y install vim 31.6s
=> [4/7] RUN yum -y install net-tools 6.2s
=> [5/7] RUN yum -y install glibc.i686 17.9s
=> [6/7] RUN mkdir /usr/local/java 0.5s
=> [7/7] ADD jdk-8u171-linux-x64.tar.gz /usr/local/java/ 11.1s
=> exporting to image 3.1s
=> => exporting layers 3.0s
=> => writing image sha256:0f64bc97e953a34834cea9da896940303d9de08d211e6fcb5ff3a6e05fdee6a6 0.0s
=> => naming to docker.io/library/centosjava8:1.5 0.0s
[root@node001 jdk]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centosjava8 1.5 0f64bc97e953 4 minutes ago 1.27GB
vluubuntu 1.2 a1ed6fe2f61e 6 days ago 118MB
node001:5000/vluubuntu 1.2 a1ed6fe2f61e 6 days ago 118MB
ubuntu 1.2 7295d0d3bc7e 6 days ago 118MB
registry.cn-hangzhou.aliyuncs.com/vlu001/myubuntu 1.3 079bf1275a8a 7 days ago 185MB
atguigu/ubuntu 3.7 7b40f602c178 7 days ago 72.8MB
hello-world <none> 9c7a54a9a43c 2 months ago 13.3kB
tomcat latest fb5657adc892 18 months ago 680MB
mysql 5.7 c20987f18b13 18 months ago 448MB
registry latest b8604a3fe854 20 months ago 26.2MB
ubuntu latest ba6acccedd29 20 months ago 72.8MB
hello-world latest feb5d9fea6a5 21 months ago 13.3kB
centos latest 5d0da3dc9764 21 months ago 231MB
redis 6.0.8 16ecd2772934 2 years ago 104MB
billygoo/tomcat8-jdk8 latest 30ef4019761d 4 years ago 523MB
[root@node001 jdk]# docker run -it 0f64bc97e953 /bin/bash
[root@b985c5c7ac7b local]# pwd
/usr/local
[root@b985c5c7ac7b local]# vim a.txt
[root@b985c5c7ac7b local]# cat a.txt
aaaAAA
[root@b985c5c7ac7b local]# vim a.txt
[root@b985c5c7ac7b local]# cat a.txt
aaaAAA
111 centOS, vim + ifconfig + java8
[root@b985c5c7ac7b local]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.2 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:ac:11:00:02 txqueuelen 0 (Ethernet)
RX packets 8 bytes 648 (648.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@b985c5c7ac7b local]# java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
[root@b985c5c7ac7b local]# [root@node001 jdk]#
[root@node001 jdk]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b985c5c7ac7b 0f64bc97e953 "/bin/bash" 2 minutes ago Up 2 minutes 80/tcp keen_heyrovsky
[root@node001 jdk]#