存储卷部署Apache网站

存储卷部署Apache网站

创建仓库
[root@Aimmi ~]# docker run  --name  centos  -dit centos /bin/bash
Unable to find image 'centos:latest' locally
latest: Pulling from library/centos
a1d0c7532777: Pull complete 
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
1ee6c6b655932051a81959536d981a1b3bec31341c5831c01ed4633a5c301ddc
[root@Aimmi ~]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS          PORTS     NAMES
1ee6c6b65593   centos    "/bin/bash"   14 seconds ago   Up 13 seconds             centos

传输httpd编译所需的资源包
[root@Aimmi ~]# ls
anaconda-ks.cfg
[root@Aimmi ~]# ls
anaconda-ks.cfg  apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.48.tar.gz
[root@Aimmi ~]# docker cp httpd-2.4.48.tar.gz  centos:/usr/src/
[root@Aimmi ~]# docker cp apr-1.7.0.tar.gz  centos:/usr/src/
[root@Aimmi ~]# docker cp apr-util-1.6.1.tar.gz  centos:/usr/src/

连接容器
[root@Aimmi ~]# docker exec  -it centos  /bin/bash
[root@1ee6c6b65593 /]# ls /usr/src/
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  debug  httpd-2.4.48.tar.gz  kernels

下载依赖包
[root@1ee6c6b65593 /]# yum -y groups mark install 'Development Tools'
[root@1ee6c6b65593 /]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make

创建用户和组
[root@1ee6c6b65593 /]# useradd -r -M -s /sbin/nologin apache

安装依赖包apr
[root@1ee6c6b65593 /]# cd /usr/src/
[root@1ee6c6b65593 src]# ls
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  debug  httpd-2.4.48.tar.gz  kernels
[root@1ee6c6b65593 src]# tar xf apr-1.7.0.tar.gz 
[root@1ee6c6b65593 src]# tar xf apr-util-1.6.1.tar.gz 
[root@1ee6c6b65593 src]# tar xf httpd-2.4.48.tar.gz 
[root@1ee6c6b65593 src]# ls
apr-1.7.0         apr-util-1.6.1         debug         httpd-2.4.48.tar.gz
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.48  kernels
[root@1ee6c6b65593 src]# cd apr-1.7.0
[root@1ee6c6b65593 apr-1.7.0]# sed -i '/$RM "$cfgfile"/d' configure
[root@1ee6c6b65593 apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@1ee6c6b65593 apr-1.7.0]# make && make install

安装依赖包apr-util
[root@1ee6c6b65593 apr-1.7.0]# cd ../apr-util-1.6.1
[root@1ee6c6b65593 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@1ee6c6b65593 apr-util-1.6.1]# make && make install

安装依赖包httpd
[root@1ee6c6b65593 apr-util-1.6.1]# cd ../httpd-2.4.48
[root@1ee6c6b65593 httpd-2.4.48]# ./configure --prefix=/usr/local/apache \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util/ \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork

[root@1ee6c6b65593 httpd-2.4.48]# make && make install


配置环境变量
[root@1ee6c6b65593 httpd-2.4.48]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@1ee6c6b65593 httpd-2.4.48]# source /etc/profile.d/httpd.sh
[root@1ee6c6b65593 httpd-2.4.48]# which httpd
/usr/local/apache/bin/httpd

头文件、man帮助
[root@1ee6c6b65593 httpd-2.4.48]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@1ee6c6b65593 httpd-2.4.48]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config

取消ServerName前面的注释,避免出现报错
[root@1ee6c6b65593 httpd-2.4.48]# sed -i '/#ServerName/s/#//g' /usr/local/apache/conf/httpd.conf

编写启动脚本
[root@1ee6c6b65593 httpd-2.4.48]# cd
[root@1ee6c6b65593 ~]# ls
anaconda-ks.cfg  anaconda-post.log  original-ks.cfg
[root@1ee6c6b65593 ~]# cd ..
[root@1ee6c6b65593 /]# ls
bin  etc   lib    lost+found  mnt  proc  run   srv  tmp  var
dev  home  lib64  media       opt  root  sbin  sys  usr
[root@1ee6c6b65593 /]# vi start.sh
[root@1ee6c6b65593 /]# chmod +x /start.sh 

制作镜像
[root@Aimmi ~]# docker commit -a 'zs <123@qq.com>' -c 'CMD ["/start.sh"]' centos httpd:v1.0
sha256:faba2d5b80a228f087b0f5d21f2f9c5379bc65b9b3b194bc0ac9fc614db26133
[root@Aimmi ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
httpd        v1.0      faba2d5b80a2   6 seconds ago   712MB
centos       latest    5d0da3dc9764   2 months ago    231MB

根据新镜像启动一个容器
[root@Aimmi ~]# docker run --name httpd -dit -p 80:80 -v /var/www/html:/usr/local/apache/htdocs  httpd:v1.0
d6d5dcc399bc00838279ab205ed0179718f2dccf4286127bcc17a2fe66a55765
[root@Aimmi ~]# docker ps
CONTAINER ID   IMAGE        COMMAND       CREATED          STATUS          PORTS                               NAMES
d6d5dcc399bc   httpd:v1.0   "/start.sh"   4 seconds ago    Up 2 seconds    0.0.0.0:80->80/tcp, :::80->80/tcp   httpd
1ee6c6b65593   centos       "/bin/bash"   13 minutes ago   Up 13 minutes                                       centos
[root@Aimmi ~]# docker exec -it httpd /bin/bash
[root@d6d5dcc399bc /]# ss -antl
State    Recv-Q   Send-Q      Local Address:Port       Peer Address:Port   Process   
LISTEN   0        128               0.0.0.0:80              0.0.0.0:*                
[root@d6d5dcc399bc /]# cd /usr/local/apache/htdocs/
[root@d6d5dcc399bc htdocs]# ls

上传网页文件
[root@Aimmi ~]# cd /var/www/html/
[root@Aimmi html]# ls
[root@Aimmi html]# ls
''$'\346\250\261\350\212\261\345\212\250\346\274\253''(P)'$'\357\274\215\344\270\223\346\263\250\345\212\250\346\274\253\347\232\204\351\227\250\346\210\267\347\275\221\347\253\231''.html'
[root@Aimmi html]# mv ''$'\346\250\261\350\212\261\345\212\250\346\274\253''(P)'$'\357\274\215\344\270\223\346\263\250\345\212\250\346\274\253\347\232\204\351\227\250\346\210\267\347\275\221\347\253\231''.html' index.html
[root@Aimmi html]# ls
index.html
[root@Aimmi html]# ls
 index.html
''$'\346\250\261\350\212\261\345\212\250\346\274\253''(P)'$'\357\274\215\344\270\223\346\263\250\345\212\250\346\274\253\347\232\204\351\227\250\346\210\267\347\275\221\347\253\231''_files'
[root@Aimmi html]# mv ''$'\346\250\261\350\212\261\345\212\250\346\274\253''(P)'$'\357\274\215\344\270\223\346\263\250\345\212\250\346\274\253\347\232\204\351\227\250\346\210\267\347\275\221\347\253\231''_files' index_files
[root@Aimmi html]# ls
index.html  index_files

查看容器中
[root@d6d5dcc399bc htdocs]# ls
index_files  index.html

存储卷部署Apache网站

 

上一篇:[转]python 多线程就这么简单


下一篇:Dockerfile