root@harbor:~/dockerfile# ll
total 8
drwxrwxr-x 4 root root 31 Apr 142021 ./
drwx------ 12 root root 4096 Jan 1917:35 ../
drwxrwxr-x 5 root root 48 Apr 142021 system/ #系统镜像
drwxrwxr-x 6 root root 59 Jan 1913:08 web/ #业务镜像root@harbor:~/dockerfile/system# cd centos/
root@harbor:~/dockerfile/system/centos# ll
total 31856
drwxrwxr-x 2 root root 122 Jan 19 09:39 ./
drwxrwxr-x 5 root root 48 Apr 142021../
-rwxrwxr-x 1 root root 145 Jan 19 09:25 build-command.sh*
-rw-r--r-- 1 root root 2523 Jan 19 09:21 Centos-7.repo
-rw-rw-r-- 1 root root 530 Jan 19 09:39 Dockerfile
-rw-r--r-- 1 root root 664 Jan 19 09:21 epel-7.repo
-rw-r--r-- 1 root root 32600353 Jan 19 09:21 filebeat-7.12.1-x86_64.rpm#基础系统镜像Dockerfile
root@harbor:~/dockerfile/system/centos# cat Dockerfile
FROM centos:7.9.2009
LABEL maintainer="wengshiqiang 2923035330@qq.com"
RUN rm-rf /etc/yum.repos.d/*
ADD Centos-7.repo /etc/yum.repos.d/
ADD epel-7.repo /etc/yum.repos.d
RUN yum clean all && yum makecache
ADD filebeat-7.12.1-x86_64.rpm /root
RUN yum install-y /root/filebeat-7.12.1-x86_64.rpm vimwget tree lrzsz gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel iproute net-tools iotop &&groupadd www -g2022&&useradd www -u2022-g www &&ln-snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime#构建镜像的脚本
root@harbor:~/dockerfile/system/centos# cat build-command.sh #!/bin/bashTAG=$1docker build -t harbor.qiange.com/baseimages/centos-base:${TAG}.docker push harbor.qiange.com/baseimages/centos-base:${TAG}# 验证
root@harbor:~/dockerfile/system/centos# docker run -it -d --rm harbor.qiange.com/baseimages/centos-base:v1
5.2 构建业务基础镜像
5.2.1 构建JDK镜像
root@harbor:~/dockerfile/web/jdk/jdk-8u-212# ll
total 190456
drwxrwxr-x 2 root root 97 Jan 19 09:43 ./
drwxrwxr-x 3 root root 24 Apr 142021../
-rwxrwxr-x 1 root root 153 Jan 19 09:43 build-command.sh*
-rw-rw-r-- 1 root root 405 Jan 19 09:41 Dockerfile
-rw-rw-r-- 1 root root 195013152 Jul 172019 jdk-8u212-linux-x64.tar.gz
-rw-rw-r-- 1 root root 2041 Apr 142021 profile#Dockerfile构建JDK
root@harbor:~/dockerfile/web/jdk/jdk-8u-212# cat Dockerfile
FROM harbor.qiange.com/baseimages/centos-base:v1
ADD jdk-8u212-linux-x64.tar.gz /usr/local/src
RUN ln-sv /usr/local/src/jdk1.8.0_212 /usr/local/jdk
ADD profile /etc/profile
ENV name wsq
ENV JAVA_HOME /usr/local/jdk
ENV JRE_HOME $JAVA_HOME/jre
ENV CLASSPATH $JAVA_HOME/lib/:$JRE_HOME/lib/
ENV PATH$PATH:$JAVA_HOME/bin#构建镜像脚本
root@harbor:~/dockerfile/web/jdk/jdk-8u-212# cat build-command.sh #!/bin/bashdocker build -t harbor.qiange.com/app-baseimages/centos-jdk-base:8u212 .docker push harbor.magedu.com/app-baseimages/centos-jdk-base:8u212#验证
root@harbor:~/dockerfile/web/jdk/jdk-8u-212# docker run -it -d --rm harbor.qiange.com/app-baseimages/centos-jdk-base:8u212 sh
02614dcf9766aa6073f3f41405c60ecc5c601f57a2a2cb950a0eab7bc1dd1a6b
root@harbor:~/dockerfile/web/jdk/jdk-8u-212# docker exec -it 02614dcf97 sh
sh-4.2# java -versionjava version "1.8.0_212"
Java(TM) SE Runtime Environment (build 1.8.0_212-b10)
Java HotSpot(TM)64-Bit Server VM (build 25.212-b10, mixed mode)
5.2.2 构建nginx基础镜像
root@harbor:~/dockerfile/web/nginx/nginx-1.25# ll
total 1196
drwxr-xr-x 2 root root 67 Jan 1912:47 ./
drwxrwxr-x 5 root root 62 Jan 1914:34 ../
-rwxr-xr-x 1 root root 142 Jan 1912:40 build.sh*
-rw-r--r-- 1 root root 458 Jan 1912:47 Dockerfile
-rw-r--r-- 1 root root 1213919 Jan 1912:39 nginx-1.25.1.tar.gz#Dockerfile构建nginx基础镜像
root@harbor:~/dockerfile/web/nginx/nginx-1.25# cat Dockerfile #Nginx Base Image
FROM harbor.qiange.com/baseimages/centos-base:v1
RUN yum install-yvimwget tree lrzsz gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel iproute net-tools iotop
ADD nginx-1.25.1.tar.gz /usr/local/src/
RUN cd /usr/local/src/nginx-1.25.1 && ./configure &&make&&makeinstall&&ln-sv /usr/local/nginx/sbin/nginx /usr/sbin/nginx &&rm-rf /usr/local/src/nginx-1.25.1.tar.gz
CMD ["nginx", "-g", "daemon off;"]#构建镜像脚本
root@harbor:~/dockerfile/web/nginx/nginx-1.25# cat build.sh #!/bin/bashdocker build -t harbor.qiange.com/app-baseimages/nginx-base:1.25 .docker push harbor.qiange.com/app-baseimages/nginx-base:1.25
5.2.3 构建tomcat基础镜像
root@harbor:~/dockerfile/web/tomcat/tomcat-base-8.5.65# ll
total 10288
drwxrwxr-x 2 root root 83 Jan 19 09:46 ./
drwxrwxr-x 5 root root 70 Apr 142021../
-rw-rw-r-- 1 root root 10523269 Mar 302021 apache-tomcat-8.5.65.tar.gz
-rwxrwxr-x 1 root root 162 Jan 19 09:46 build-command.sh*
-rw-rw-r-- 1 root root 168 Jan 19 09:46 Dockerfile#Dockerfile构建tomcat基础镜像
root@harbor:~/dockerfile/web/tomcat/tomcat-base-8.5.65# cat Dockerfile #tomcat base image
FROM harbor.qiange.com/app-baseimages/centos-jdk-base:8u212
ADD apache-tomcat-8.5.65.tar.gz /apps
RUN ln-sv /apps/apache-tomcat-8.5.65 /apps/tomcat#构建镜像脚本
root@harbor:~/dockerfile/web/tomcat/tomcat-base-8.5.65# cat build-command.sh #!/bin/bashdocker build -t harbor.qiange.com/app-baseimages/tomcat-centos-base:v8.5.65 .docker push harbor.qiange.com/app-baseimages/tomcat-centos-base:v8.5.65
5.2.4验证镜像是否可用犯得错
故障现象:镜像打好后,使用docker run -it $image sh进入容器后,发现dockerfile中指定的CMD命令没有生效,在容器里启动服务,服务是可以正常启动,一直误认为是自己打的镜像有问题。故障原因:
1、docker run -it $image 没有执行shell时,容器运行后会运行dockerfile中指定的CMD命令
2、docker run -it $image sh 当你运行容器运行shell命令后,相当于重写默认的CMD指令,导致容器以shell命令为入口启动,把dockerfile中指定的CMD指令覆盖了注意:两种运行容器的方式细微的差别,但是结果相差很大解决方案:
docker run -it $image
docker exec -it $containerID sh
此时进入容器后,就会发现原先的CMD指定的服务启动指令生效注意:有的服务需要指定驻守进程(如在容器启动时一直执行一个进程,tail -f /etc/hosts)
流式读取文件数据 from pyspark.sql import SparkSession
ss SparkSession.builder.getOrCreate()
# todo 注意1:流式读取目录下的文件 --》一定一定要是目录,不是具体的文件,# 目录下产生新文件会进行读取# todo 注意点2࿱…
121 Best Time to Buy and Sell Stock (买卖股票的最佳时机)
你好,2024年的第一个月,又是秋风萧瑟天气凉,草木摇落露为霜。.。。在这个特殊的时代,作为我们普通的一个打工人,我们用这道题,开启对这个不符合…