[root@localhost ~]# tree haproxy/ haproxy/ ├── dockerfile └── files ├── env.txt ├── haproxy-2.5.0.tar.gz ├── haproxycfg.sh ├── install.sh └── sysctl.conf 1 directory, 6 files [root@localhost ~]#2. 编写dockerfile
[root@localhost ~]# cd haproxy/ [root@localhost haproxy]# cat dockerfile FROM alpine LABEL MAINTAINER "lry 1@2qq.com" ENV version 2.5.0 ADD files/haproxy-${version}.tar.gz /tmp/ ADD files/install.sh /tmp/ ADD files/haproxycfg.sh /tmp/ ADD files/sysctl.conf /tmp/ RUN /tmp/install.sh ENTRYPOINT /tmp/haproxycfg.sh [root@localhost haproxy]#3. 配置文件
[root@localhost haproxy]# cd files/ [root@localhost files]# ls env.txt haproxy-2.5.0.tar.gz haproxycfg.sh install.sh sysctl.conf //RS ip [root@localhost files]# cat env.txt RSs=172.17.0.2 172.17.0.3 //内核参数 [root@localhost files]# cat 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 //安装脚本 [root@localhost files]# cat 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 /tmp/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 /tmp/haproxy-${version}/ /tmp/install.sh //haproxy配置文件 [root@localhost files]# cat haproxycfg.sh #!/bin/sh cat > /etc/haproxy/haproxy.cfg <> /etc/haproxy/haproxy.cfg < 4. 构建镜像 [root@localhost haproxy]# docker build -t haproxy:v1.0 . .........忽略N行 (1/10) Purging gcc (10.3.1_git20211027-r0) (2/10) Purging binutils (2.37-r3) (3/10) Purging libatomic (10.3.1_git20211027-r0) (4/10) Purging libgomp (10.3.1_git20211027-r0) (5/10) Purging libgphobos (10.3.1_git20211027-r0) (6/10) Purging make (4.3-r0) (7/10) Purging mpc1 (1.2.1-r0) (8/10) Purging mpfr4 (4.1.0-r0) (9/10) Purging isl22 (0.22-r0) (10/10) Purging gmp (6.2.1-r0) Executing busybox-1.34.1-r3.trigger OK: 35 MiB in 45 packages Removing intermediate container 7d2ec6aa8327 ---> c9813eff9a55 Step 9/9 : ENTRYPOINT /tmp/haproxycfg.sh ---> Running in 54c3e78ce2d5 Removing intermediate container 54c3e78ce2d5 ---> bc383740a37a Successfully built bc383740a37a Successfully tagged haproxy:v1.0 [root@localhost haproxy]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE haproxy v1.0 bc383740a37a 2 minutes ago 85.1MB alpine latest c059bfaa849c 2 weeks ago 5.59MB [root@localhost haproxy]#6. 创建容器//创建apache和nginx容器 [root@localhost haproxy]# docker run -d --name apache httpd Unable to find image 'httpd:latest' locally latest: Pulling from library/httpd e5ae68f74026: Pull complete bc36ee1127ec: Pull complete d3576f2b6317: Pull complete f1aa5f54b226: Pull complete aa379c0cedc2: Pull complete Digest: sha256:fba8a9f4290180ceee5c74638bb85ff21fd15961e6fdfa4def48e18820512bb1 Status: Downloaded newer image for httpd:latest dc5872009f97f546fbd54856d7a40c65ff13c1c60af0122470a18a357cb36cea [root@localhost haproxy]# docker run -d --name nginx nginx Unable to find image 'nginx:latest' locally latest: Pulling from library/nginx e5ae68f74026: Already exists 21e0df283cd6: Pull complete ed835de16acd: Pull complete 881ff011f1c9: Pull complete 77700c52c969: Pull complete 44be98c0fab6: Pull complete Digest: sha256:9522864dd661dcadfd9958f9e0de192a1fdda2c162a35668ab6ac42b465f0603 Status: Downloaded newer image for nginx:latest 1f4fed0191c810938072da3c6bfc70d2a73ea7ff3b4bcbf7144ce6a51896405b [root@localhost haproxy]# docker ps ConTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1f4fed0191c8 nginx "/docker-entrypoint.…" 23 seconds ago Up 22 seconds 80/tcp nginx dc5872009f97 httpd "httpd-foreground" about a minute ago Up about a minute 80/tcp apache [root@localhost haproxy]#//查看apache ip [root@localhost haproxy]# docker inspect apache ......省略N行 "NetworkID": "18039c5e5ccec90bd886bf585700422392db62dbd2258ca378cf4eee1abc3f9f", "EndpointID": "00bf38a60b64a858bbd35e445cc76e51ad70c58e6c11504d6c2a991c81b829af", "Gateway": "172.17.0.1", "IPAddress": "172.17.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", ......省略N行//查看nginx ip [root@localhost haproxy]# docker inspect nginx ......省略N行 "NetworkID": "18039c5e5ccec90bd886bf585700422392db62dbd2258ca378cf4eee1abc3f9f", "EndpointID": "0c34b972284c0dca798fa15173aee2c2da333b90f484bf161f3f68ab8cff2fbd", "Gateway": "172.17.0.1", "IPAddress": "172.17.0.3", "IPPrefixLen": 16, "IPv6Gateway": "", ......省略N行//填写RS ip [root@localhost haproxy]# cat files/env.txt RSs=172.17.0.2 172.17.0.3 [root@localhost haproxy]# //利用haproxyv:1.0镜像创建容器 [root@localhost haproxy]# docker run -d --name haproxy -p 8080:80 --env-file files/env.txt haproxy:v1.0 dc201555c9810abebb6037319db127d99db72cf64161e1fbefc6c5f3c7eefb78 [root@localhost haproxy]# docker ps ConTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dc201555c981 haproxy:v1.0 "/bin/sh -c /tmp/hap…" 8 seconds ago Up 7 seconds 0.0.0.0:8080->80/tcp, :::8080->80/tcp haproxy 1f4fed0191c8 nginx "/docker-entrypoint.…" 10 minutes ago Up 10 minutes 80/tcp nginx dc5872009f97 httpd "httpd-foreground" 10 minutes ago Up 10 minutes 80/tcp apache [root@localhost haproxy]# docker port haproxy 80/tcp -> 0.0.0.0:8080 80/tcp -> :::8080 [root@localhost haproxy]#7. 访问[root@localhost ~]# curl 192.168.35.135:8080 It works! [root@localhost ~]# curl 192.168.35.135:8080Welcome to nginx! html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } Welcome to nginx! If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.Thank you for using nginx.
[root@localhost ~]#欢迎分享,转载请注明来源:内存溢出
评论列表(0条)