业务基础镜像

centos基础镜像 15154213303/centos-base:2024-2-24

root@zhaohuakang:centos# cat build-command.sh 
#!/bin/bash
TAG=$1
docker build -t 15154213303/centos-base:${TAG} .
docker push 15154213303/centos-base:${TAG}
root@zhaohuakang:centos# cat Dockerfile 
FROM centos:7.8.2003

LABEL maintainer="zhaohuakang 2718354047@qq.com"


RUN yum install -y wget && mkdir -p /etc/yum.repos.d/bak && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/ && wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo && wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo && yum clean all && yum makecache && yum install -y vim  tree  lrzsz gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel iproute net-tools iotop &&  groupadd www -g 2022 && useradd www -u 2022 -g www && rm -rf /var/cache/yum/* && rm -f  /etc/localtime && ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
root@zhaohuakang:centos# bash build-command.sh 2024-2-24

nginx镜像 15154213303/centos-nginx:1.22

root@zhaohuakang:nginx# cat build.sh 
#!/bin/bash
tag=$1
docker build -t 15154213303/centos-nginx:$tag . 
docker push 15154213303/centos-nginx:$tag
root@zhaohuakang:nginx# cat Dockerfile 
FROM 15154213303/centos-base:2024-2-24
LABEL author=zhaohuakang
ENV NGINX_VERSION=1.22.0
ADD nginx-${NGINX_VERSION}.tar.gz /usr/local
RUN yum -y install gcc make gcc-c++ libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel  && \
    rm -rf /var/cache/yum/* && \
    cd /usr/local/nginx-${NGINX_VERSION} && \
    ./configure --prefix=/apps/nginx  && \
    make && make install && \
    rm -rf /usr/local/nginx* 
COPY nginx.conf /apps/nginx/conf/
VOLUME ["/data/nginx/html"]
EXPOSE 80
CMD /apps/nginx/sbin/nginx -g "daemon off;"
COPY *.html /data/nginx/html/
root@zhaohuakang:nginx# cat index.html 
<h1>  welcome to docker website </h1>
root@zhaohuakang:nginx# egrep -v "#|^$" nginx.conf
user  www;
worker_processes  auto;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   /data/nginx/html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
root@zhaohuakang:nginx# bash build.sh 

jdk镜像 15154213303/centos-jdk-base:8u212

root@zhaohuakang:jdk-8u-212# ls
build-command.sh  Dockerfile  jdk-8u212-linux-x64.tar.gz  profile
root@zhaohuakang:jdk-8u-212# cat build-command.sh 
#!/bin/bash
docker build -t 15154213303/centos-jdk-base:8u212 .
docker push 15154213303/centos-jdk-base:8u212
root@zhaohuakang:jdk-8u-212# cat Dockerfile 
FROM 15154213303/centos-base:2024-2-24

LABEL maintainer="zhaohuakang 2718354047@qq.com"
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 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@zhaohuakang:jdk-8u-212# cat profile 
# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

pathmunge () {
    case ":${PATH}:" in
        *:"$1":*)
            ;;
        *)
            if [ "$2" = "after" ] ; then
                PATH=$PATH:$1
            else
                PATH=$1:$PATH
            fi
    esac
}


if [ -x /usr/bin/id ]; then
    if [ -z "$EUID" ]; then
        # ksh workaround
        EUID=`/usr/bin/id -u`
        UID=`/usr/bin/id -ru`
    fi
    USER="`/usr/bin/id -un`"
    LOGNAME=$USER
    MAIL="/var/spool/mail/$USER"
fi

# Path manipulation
if [ "$EUID" = "0" ]; then
    pathmunge /usr/sbin
    pathmunge /usr/local/sbin
else
    pathmunge /usr/local/sbin after
    pathmunge /usr/sbin after
fi

HOSTNAME=`/usr/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
    export HISTCONTROL=ignoreboth
else
    export HISTCONTROL=ignoredups
fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL

# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
    umask 002
else
    umask 022
fi

for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
    if [ -r "$i" ]; then
        if [ "${-#*i}" != "$-" ]; then 
            . "$i"
        else
            . "$i" >/dev/null
        fi
    fi
done

unset i
unset -f pathmunge

export JAVA_HOME=/usr/local/jdk
export TOMCAT_HOME=/apps/tomcat
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$TOMCAT_HOME/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
root@zhaohuakang:jdk-8u-212# bash build-command.sh 

tomcat基础镜像 15154213303/tomcat-centos-base:v8.5.65

root@zhaohuakang:tomcat-base-8.5.65# ls
apache-tomcat-8.5.65.tar.gz  build-command.sh  Dockerfile
root@zhaohuakang:tomcat-base-8.5.65# cat build-command.sh 
#!/bin/bash
docker build -t 15154213303/tomcat-centos-base:v8.5.65 .
docker push 15154213303/tomcat-centos-base:v8.5.65
root@zhaohuakang:tomcat-base-8.5.65# cat Dockerfile 
FROM 15154213303/centos-jdk-base:8u212

LABEL maintainer="zhaohuakang 2718354047@qq.com"

ADD apache-tomcat-8.5.65.tar.gz /apps
RUN ln -sv /apps/apache-tomcat-8.5.65 /apps/tomcat
root@zhaohuakang:tomcat-base-8.5.65# bash build-command.sh 

tomcat业务镜像1 15154213303/tomcat-m43:app1

root@zhaohuakang:tomcat# ls
build-command.sh  Dockerfile  myapp  myapp.tar.gz  run_tomcat.sh  server.xml  
root@zhaohuakang:tomcat# chmod +x run_tomcat.sh 
root@zhaohuakang:tomcat# cat build-command.sh 
#!/bin/bash
docker build -t 15154213303/tomcat-m43:app1 .
docker push 15154213303/tomcat-m43:app1
root@zhaohuakang:tomcat# cat build-command.sh 
#!/bin/bash
docker build -t 15154213303/tomcat-m43:app1 .
docker push 15154213303/tomcat-m43:app1
root@zhaohuakang:tomcat# cat Dockerfile 
#magedu m43 tomcat app1
FROM 15154213303/tomcat-centos-base:v8.5.65

LABEL maintainer="jack 2973707860@qq.com" 

ADD run_tomcat.sh /apps/tomcat/bin/run_tomcat.sh
ADD server.xml /apps/tomcat/conf/server.xml
ADD myapp.tar.gz /data/tomcat/webapps


RUN chown www.www /data /apps -R

EXPOSE 8080 8443

CMD ["/apps/tomcat/bin/run_tomcat.sh"]
root@zhaohuakang:tomcat# cat run_tomcat.sh 
#!/bin/bash
su - www -c "/apps/tomcat/bin/catalina.sh start"
tail -f /etc/hosts
root@zhaohuakang:tomcat# cat server.xml 
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443
         This connector uses the NIO implementation. The default
         SSLImplementation will depend on the presence of the APR/native
         library and the useOpenSSL attribute of the
         AprLifecycleListener.
         Either JSSE or OpenSSL style configuration may be used regardless of
         the SSLImplementation selected. JSSE style configuration is used below.
    -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true">
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    -->
    <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
         This connector uses the APR/native implementation which always uses
         OpenSSL for TLS.
         Either JSSE or OpenSSL style configuration may be used. OpenSSL style
         configuration is used below.
    -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
               maxThreads="150" SSLEnabled="true" >
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
                         certificateFile="conf/localhost-rsa-cert.pem"
                         certificateChainFile="conf/localhost-rsa-chain.pem"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <!--
    <Connector protocol="AJP/1.3"
               address="::1"
               port="8009"
               redirectPort="8443" />
    -->

    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="localhost">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="/data/tomcat/webapps"   unpackWARs="false" autoDeploy="false">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>
root@zhaohuakang:tomcat# ll myapp
total 12
drwxr-xr-x 2 root root 4096 Apr 14  2021 ./
drwxr-xr-x 5 root root 4096 Feb 24 23:18 ../
-rw-r--r-- 1 root root   41 Apr 14  2021 index.jsp
root@zhaohuakang:tomcat# bash build-command.sh 

启动访问
docker run -d -p 8080:8080 15154213303/tomcat-m43:app1
http://10.0.0.10:8080/myapp/

tomcat业务镜像2 15154213303/tomcat-m43:app2 拿jpress为例子,如果要去掉访问路径参考
https://blog.51cto.com/dayu/5798598 就是把war包变成ROOT.war
server.xml和之前的有区别
<Host name="localhost" appBase="/data/tomcat/webapps" unpackWARs="true" autoDeploy="false">

root@zhaohuakang:tomcat-app2# ls
build-command.sh  Dockerfile  jpress-v4.0.7.war    run_tomcat.sh  server.xml
root@zhaohuakang:tomcat-app2# chmod +x run_tomcat.sh 
root@zhaohuakang:tomcat-app2# cat build-command.sh 
#!/bin/bash
docker build -t 15154213303/tomcat-m43:app2 .
docker push 15154213303/tomcat-m43:app2
root@zhaohuakang:tomcat-app2# cat Dockerfile 
FROM 15154213303/tomcat-centos-base:v8.5.65

LABEL maintainer="jack 2973707860@qq.com" 

ADD run_tomcat.sh /apps/tomcat/bin/run_tomcat.sh
ADD server.xml /apps/tomcat/conf/server.xml
ADD jpress-v4.0.7.war /data/tomcat/webapps/jpress.war


RUN chown www.www /data /apps -R

EXPOSE 8080 8443

CMD ["/apps/tomcat/bin/run_tomcat.sh"]
root@zhaohuakang:tomcat-app2# cat run_tomcat.sh 
#!/bin/bash
su - www -c "/apps/tomcat/bin/catalina.sh start"
tail -f /etc/hosts
root@zhaohuakang:tomcat-app2# cat server.xml 
      <Host name="localhost"  appBase="/data/tomcat/webapps"   unpackWARs="true" autoDeploy="false">

root@zhaohuakang:tomcat-app2# bash build-command.sh 

启动容器访问
docker run -ti -d 8080:8080 15154213303/tomcat-m43:app2
http://10.0.0.10:8080/jpress

haproxy镜像

root@zhaohuakang:haproxy# ls
build-command.sh  Dockerfile  haproxy-2.2.11.tar.gz  haproxy.cfg  run_haproxy.sh
root@zhaohuakang:haproxy# chmod +x run_haproxy.sh 
root@zhaohuakang:haproxy# cat build-command.sh 
#!/bin/bash
docker build -t 15154213303/haproxy:v2.2.11 .
docker push 15154213303/haproxy:v2.2.11
root@zhaohuakang:haproxy# cat Dockerfile 
FROM 15154213303/centos-base:2024-2-24

LABEL maintainer="jack 2973707860@qq.com"

RUN yum install libtermcap-devel ncurses-devel libevent-devel readline-devel  gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl  openssl-devel systemd-devel net-tools vim iotop bc  zip unzip zlib-devel lrzsz tree screen lsof tcpdump wget ntpdate -y

ADD haproxy-2.2.11.tar.gz /usr/local/src

RUN cd /usr/local/src/haproxy-2.2.11 && make  ARCH=x86_64 TARGET=linux-glibc  USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1  USE_SYSTEMD=1  USE_CPU_AFFINITY=1 PREFIX=/apps/haproxy && make install PREFIX=/apps/haproxy && cp haproxy  /usr/sbin/ && mkdir /apps/haproxy/run -p 

ADD run_haproxy.sh /apps/haproxy/bin/run_haproxy.sh
ADD haproxy.cfg /etc/haproxy/haproxy.cfg

EXPOSE 80 9999

CMD ["/apps/haproxy/bin/run_haproxy.sh"]
root@zhaohuakang:haproxy# cat haproxy.cfg 
global
chroot /apps/haproxy
#stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin
uid 99
gid 99
daemon
nbproc 1
pidfile /apps/haproxy/run/haproxy.pid
log 127.0.0.1 local3 info

defaults
option http-keep-alive
option  forwardfor
mode http
timeout connect 300000ms
timeout client  300000ms
timeout server  300000ms

listen stats
 mode http
 bind 0.0.0.0:9999
 stats enable
 log global
 stats uri     /haproxy-status
 stats auth    haadmin:123456

listen  web_port
 bind 0.0.0.0:80
 mode http
 log global
 balance roundrobin
 server web1  10.0.0.10:8080  check inter 3000 fall 2 rise 5
root@zhaohuakang:haproxy# cat run_haproxy.sh 
#!/bin/bash
/apps/haproxy/sbin/haproxy  -f /etc/haproxy/haproxy.cfg

tail -f /etc/hosts
root@zhaohuakang:haproxy# bash build-command.sh 

启动访问
root@zhaohuakang:haproxy# docker run -d -p 80:80 15154213303/haproxy:v2.2.11
http://10.0.0.10/jpress

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容