最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Dockerfile如何使用alpine系統(tǒng)制作haproxy鏡像

 更新時間:2023年05月30日 08:42:51   作者:slyybw  
這篇文章主要介紹了Dockerfile如何使用alpine系統(tǒng)制作haproxy鏡像問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

Dockerfile目錄結(jié)構(gòu)

[root@localhost ~]# tree haproxy_alpinelinux/
haproxy_alpine/
├── Dockerfile
└── files
    ├── haproxy-2.4.0.tar.gz
    ├── haproxycfg.sh
    ├── install.sh
    └── sysctl.conf
1 directory, 5 files

拉取alpine鏡像

[root@localhost ~]# 
[root@localhost ~]# docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
Digest: sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300
Status: Image is up to date for alpine:latest
docker.io/library/alpine:latest
[root@localhost ~]# docker images
REPOSITORY         TAG       IMAGE ID       CREATED          SIZE
alpine             latest    c059bfaa849c   2 weeks ago      5.59MB

Dockerfile文件內(nèi)容

[root@localhost ~]# cat haproxy_alpine/Dockerfile 
FROM alpine
LABEL MAINTAINER "syblyw0806 1234567890@qqq.com"
ENV version 2.4.0
ADD files/haproxy-${version}.tar.gz /opt/
ADD files/install.sh /opt/
ADD files/haproxycfg.sh /opt/
ADD files/sysctl.conf /opt/
RUN /opt/install.sh
ENTRYPOINT /opt/haproxycfg.sh

安裝haproxy的腳本

[root@localhost ~]# cat haproxy_alpine/files/install.sh 
#!/bin/sh
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/' /etc/apk/repositories
apk update
adduser -S -H -s /sbin/nologin haproxy
addgroup haproxy
apk add --no-cache -U make gcc pcre-dev bzip2-dev openssl-dev elogind-dev libc-dev dahdi-tools dahdi-tools-dev libexecinfo libexecinfo-dev ncurses-dev zlib-dev zlib
cd /opt/haproxy-${version}
make TARGET=linux-musl USE_OPENSSL=1 USE_ZLIB=1 USE_PCRE=1 
make install PREFIX=/usr/local/haproxy
cp haproxy  /usr/sbin/
mkdir /etc/haproxy
apk del gcc make
rm -rf /opt/haproxy-${version}/ /opt/install.sh

haproxy配置文件

[root@localhost ~]# cat haproxy_alpine/files/haproxycfg.sh 
#!/bin/sh
cat > /etc/haproxy/haproxy.cfg <<EOF
#--------------????----------------
global
    log 127.0.0.1 local0  info
    #log loghost local0 info
    maxconn 20480
#chroot /usr/local/haproxy
    pidfile /var/run/haproxy.pid
    #maxconn 4000
    user haproxy
    group haproxy
    daemon
#---------------------------------------------------------------------
#common defaults that all the 'listen' and 'backend' sections will
#use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode http
    log global
    option dontlognull
    option httpclose
    option httplog
    #option forwardfor
    option redispatch
    balance roundrobin
    timeout connect 10s
    timeout client 10s
    timeout server 10s
    timeout check 10s
    maxconn 60000
    retries 3
#--------------??????------------------
listen admin_stats
    bind 0.0.0.0:8189
    stats enable
    mode http
    log global
    stats uri /haproxy_stats
    stats realm Haproxy\ Statistics
    stats auth admin:admin
    #stats hide-version
    stats admin if TRUE
    stats refresh 30s
#---------------web??-----------------------
listen webcluster
    bind 0.0.0.0:80
    mode http
    #option httpchk GET /index.html
    log global
    maxconn 3000
    balance roundrobin
    cookie SESSION_COOKIE insert indirect nocache
EOF
count=1
for rs_ip in $RSs;do
cat >> /etc/haproxy/haproxy.cfg <<EOF
    server web$count $rs_ip:80 check inter 2000 fall 5
EOF
let count++
done
haproxy -f  /etc/haproxy/haproxy.cfg -db

sysctl.conf

[root@localhost ~]# cat haproxy_alpine/files/sysctl.conf 
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.ip_forward = 1

構(gòu)建鏡像

[root@localhost ~]# docker build -t haproxy:v3.0 haproxy_alpinelinux/
Sending build context to Docker daemon  3.602MB
Step 1/9 : FROM alpine
 ---> c059bfaa849c
Step 2/9 : LABEL MAINTAINER "syblyw0806 1234567890@qqq.com"
 ---> Using cache
 ---> bbfbe82a7f48
Step 3/9 : ENV version 2.4.0
 ---> Using cache
 ---> dccb41beb82b
Step 4/9 : ADD files/haproxy-${version}.tar.gz /opt/
 ---> Using cache
 ---> 856cb1d8e0de
Step 5/9 : ADD files/install.sh /opt/
 ---> 589a939efe69
Step 6/9 : ADD files/haproxycfg.sh /opt/
 ---> 37bd73459586
Step 7/9 : ADD files/sysctl.conf /opt/
 ---> be1b5cd53414
Step 8/9 : RUN /opt/install.sh
 ---> Running in 6fd54c54e040
 Removing intermediate container 6fd54c54e040
 ---> e1bf872ca416
Step 9/9 : ENTRYPOINT /opt/haproxycfg.sh
 ---> Running in 89515ad8dc41
Removing intermediate container 89515ad8dc41
 ---> 4f4d41c2eebb
Successfully built 4f4d41c2eebb
Successfully tagged haproxy:v3.0
[root@localhost ~]# docker images
REPOSITORY         TAG       IMAGE ID       CREATED             SIZE
haproxy            v3.0      4f4d41c2eebb   About an hour ago   83.8MB

啟動容器

[root@localhost ~]# docker run -d --name haproxy_alpinelinux -p 1234:80 -e RSs="172.17.0.2 172.17.0.3" haproxy:v3.0
// 啟動一個httpd容器和一個nginx容器
be589a4d9689427ec0810c2f2b28aa59dd4bba425590f0277b4e4f82d3b973e8
[root@localhost ~]# docker run -d --name httpd syblyw0806/httpd:v2.0 
0706632d35fbf02807c5668cae27fc8d3fe3406f198dff5988370c688c630b5b
[root@localhost ~]# docker run -d --name nginx nginx
80ccbde27a8e0d5545b8422f809c9b09f178bff7a20d5bc194925bd707a34af7
[root@localhost ~]# docker exec -it haproxy_alpinelinux /bin/sh
/ # ss -anlt     // 這里如果沒有ss命令,需要安裝iproute2這個包
State         Recv-Q        Send-Q                Local Address:Port                 Peer Address:Port        Process        
LISTEN        0             128                         0.0.0.0:8189                      0.0.0.0:*                          
LISTEN        0             128                         0.0.0.0:80                        0.0.0.0:*                          
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE                   COMMAND                  CREATED              STATUS              PORTS                                   NAMES
be589a4d9689   haproxy:v3.0            "/bin/sh -c /opt/hap…"   About a minute ago   Up About a minute   0.0.0.0:1234->80/tcp, :::1234->80/tcp   haproxy_alpinelinux
80ccbde27a8e   nginx                   "/docker-entrypoint.…"   10 minutes ago       Up 10 minutes       80/tcp                                  nginx
0706632d35fb   syblyw0806/httpd:v2.0   "/usr/local/apache/b…"   10 minutes ago       Up 10 minutes       80/tcp                                  httpd

訪問測試

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 從入門到生產(chǎn)級配置詳解Docker部署Nginx的實戰(zhàn)指南

    從入門到生產(chǎn)級配置詳解Docker部署Nginx的實戰(zhàn)指南

    Nginx 作為高性能的 HTTP 服務(wù)器和反向代理服務(wù)器,在 Web 架構(gòu)中占據(jù)著核心地位,本文將帶你從零開始學(xué)習(xí)使用?Docker?容器化部署?Nginx?的完整流程,有需要的小伙伴可以了解下
    2026-05-05
  • Docker-compose搭建Redis集群(Sentinel)的實現(xiàn)

    Docker-compose搭建Redis集群(Sentinel)的實現(xiàn)

    本文主要介紹了Docker-compose搭建Redis集群(Sentinel)的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-07-07
  • 使用minikube安裝使用單機版K8S方式(docker)

    使用minikube安裝使用單機版K8S方式(docker)

    本文介紹了如何在centos7上使用minikube快速搭建單機版k8s,主要步驟包括:下載kubectl和docker,創(chuàng)建新用戶,下載和安裝minikube,驗證安裝情況,最后,通過執(zhí)行minikube和minikubestop啟停K8s,或使用minikubedelete徹底刪除K8S的數(shù)據(jù)
    2024-10-10
  • docker安裝Redis高可用實現(xiàn)一主二從三哨兵

    docker安裝Redis高可用實現(xiàn)一主二從三哨兵

    redis提供了哨兵模式保證redis實現(xiàn)高可用,本文主要介紹了docker安裝Redis高可用實現(xiàn)一主二從三哨兵,文中通過示例代碼介紹的非常詳細(xì),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-02-02
  • docker修改容器配置文件的3種方法總結(jié)

    docker修改容器配置文件的3種方法總結(jié)

    有時候可能需要修改運行在docker容器中的nginx的配置文件,或者其他一些已經(jīng)運行和啟動很久的容器中的配置文件,下面這篇文章主要給大家介紹了關(guān)于docker修改容器配置文件的3種方法,需要的朋友可以參考下
    2022-04-04
  • Docker數(shù)據(jù)卷常用操作代碼實例

    Docker數(shù)據(jù)卷常用操作代碼實例

    這篇文章主要介紹了Docker數(shù)據(jù)卷常用操作代碼實例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-10-10
  • 使用Docker快速搭建你的Gitbook

    使用Docker快速搭建你的Gitbook

    這篇文章主要介紹了使用Docker快速搭建你的Gitbook的相關(guān)資料,需要的朋友可以參考下
    2023-11-11
  • docker修改默認(rèn)存儲路徑和網(wǎng)段的操作過程

    docker修改默認(rèn)存儲路徑和網(wǎng)段的操作過程

    本文介紹了如何修改Docker的數(shù)據(jù)目錄和默認(rèn)網(wǎng)段,以避免與其他系統(tǒng)或應(yīng)用的網(wǎng)絡(luò)配置沖突,詳細(xì)步驟包括停止Docker服務(wù)、修改Docker配置文件、復(fù)制或移動現(xiàn)有數(shù)據(jù)到新目錄、重啟Docker服務(wù)以及驗證設(shè)置
    2025-12-12
  • Docker實現(xiàn)發(fā)布一個springboot項目

    Docker實現(xiàn)發(fā)布一個springboot項目

    文章介紹了使用Docker打包SpringBoot項目的過程,包括基本用法、maven源碼打包法、使用maven插件打包和docker-maven-plugin插件打包,并詳細(xì)講述了每種方法的操作步驟和配置細(xì)節(jié),最后總結(jié)了使用插件打包的優(yōu)勢
    2026-04-04
  • docker容器訪問GPU資源的使用指南

    docker容器訪問GPU資源的使用指南

    nvidia-docker 和 nvidia-container-runtime 是用于在 NVIDIA GPU 上運行 Docker 容器的兩個相關(guān)工具,它們的作用是提供 Docker 容器與 GPU 加速硬件的集成支持,本文給大家介紹了docker容器訪問GPU資源的使用指南,需要的朋友可以參考下
    2024-02-02

最新評論

霍城县| 西平县| 财经| 洪江市| 桓仁| 抚州市| 神农架林区| 扶余县| 洪雅县| 乌鲁木齐县| 呼图壁县| 沛县| 上栗县| 富阳市| 彭泽县| 南和县| 旅游| 方山县| 沧州市| 营口市| 屏山县| 湖州市| 安化县| 溧水县| 萝北县| 霍山县| 米易县| 论坛| 宝山区| 江达县| 和田市| 平顺县| 新宁县| 江陵县| 环江| 翁源县| 临漳县| 新建县| 榆林市| 铁岭市| 石城县|