docker(12):dockerfile构建kodexplorer(可道云)

docker(12):dockerfile构建kodexplorer(可道云)

KodExplorer是一款快捷高效的私有云和在线文档管理系统,为个人网站、企业私有云部署、网络存储、在线文档管理、在线办公等提供安全可控,简便易用、可高度定制的私有云产品。采用windows风格界面、操作习惯,无需适应即可快速上手,支持几百种常用文件格式的在线预览,可扩展易定制。GPL v3开源协议。

1 手动安装

1.1 环境

项目:可道云网盘kodexplorer
需要的环境:httpd+php或者nginx+php
php所需模块:php5.5以上
基础镜像:centos:7.6
项目下载地址: http://static.kodcloud.com/update/download/kodexplorer4.37.zip
项目官网:https://kodcloud.com/download/

 

1.2 安装服务软件

基础环境

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
sed -i 's#$releasever#7#g' /etc/yum.repos.d/CentOS-Base.repo
sed -i 's#$basearch#x86_64#g' /etc/yum.repos.d/CentOS-Base.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum install nginx net-tools php-cli php-fpm unzip php-gd php-mbstring -y

 

调试 PHP info

PHP换成Nginx用户
[root@0fd3f853ea4b /]# grep -n nginx  /etc/php-fpm.d/www.conf         
39:user = nginx
41:group = nginx
[root@0fd3f853ea4b /]#

 

启动php-fpm
[root@0fd3f853ea4b /]# systemctl  start php-fpm
[root@0fd3f853ea4b /]# ps -ef | grep php
root       3690      1  1 02:30 ?        00:00:00 php-fpm: master process (/etc/php-fpm.conf)
nginx      3691   3690  0 02:30 ?        00:00:00 php-fpm: pool www
nginx      3692   3690  0 02:30 ?        00:00:00 php-fpm: pool www
nginx      3693   3690  0 02:30 ?        00:00:00 php-fpm: pool www
nginx      3694   3690  0 02:30 ?        00:00:00 php-fpm: pool www
nginx      3695   3690  0 02:30 ?        00:00:00 php-fpm: pool www
root       3697   3352  0 02:30 pts/0    00:00:00 grep --color=auto php
[root@0fd3f853ea4b /]#

 

配置Nginx支持PHP
[root@0fd3f853ea4b html]# cat /etc/nginx/nginx.conf
worker_processes  1;
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   html;
            index index.php index.html index.htm;
        }
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}

 

 

写一个PHP测试页
[root@0fd3f853ea4b html]# pwd
/usr/share/nginx/html
[root@0fd3f853ea4b html]# cat index.php 
<?php phpinfo(); ?>
[root@0fd3f853ea4b html]#

 

 

启动nginx
[root@0fd3f853ea4b nginx]# systemctl  start nginx
[root@0fd3f853ea4b nginx]# ps -ef | grep nginx
nginx      3691   3690  0 02:30 ?        00:00:00 php-fpm: pool www
nginx      3692   3690  0 02:30 ?        00:00:00 php-fpm: pool www
nginx      3693   3690  0 02:30 ?        00:00:00 php-fpm: pool www
nginx      3694   3690  0 02:30 ?        00:00:00 php-fpm: pool www
nginx      3695   3690  0 02:30 ?        00:00:00 php-fpm: pool www
root       3712      1  0 02:35 ?        00:00:00 nginx: master process /usr/sbin/nginx
nginx      3713   3712  0 02:35 ?        00:00:00 nginx: worker process
root       3717   3352  0 02:36 pts/0    00:00:00 grep --color=auto nginx
[root@0fd3f853ea4b nginx]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      3690/php-fpm: maste 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      3712/nginx: master  
[root@0fd3f853ea4b nginx]#

 

测试

 

 

 

1.3 部署可道云

cd /usr/share/nginx/html
mkdir bak
mv 404.html 50x.html nginx-logo.png index.* poweredby.png bak/
curl -o kodexplorer.zip http://static.kodcloud.com/update/download/kodexplorer4.37.zip
unzip kodexplorer.zip
su -c 'setenforce 0'
chown -R nginx:nginx  /usr/share/nginx/html/

 

 

 

 

 

1.4 提交镜像

[root@docker-136 ~]# docker commit kod-1  kod:v1
sha256:681c97c0548e69f89f83e1437a798430d461e8ca9669b1011b6f0ced5c73cc9e
[root@docker-136 ~]# docker images|grep kod
kod                           v1                  681c97c0548e        42 seconds ago      550MB
[root@docker-136 ~]#

 

 

 

1.5 测试镜像

[root@docker-136 ~]# docker run --privileged=true -d  -p 1080:80  --name kod-2  kod:v1 /usr/sbin/init           
df9af7f7cb15815abd8876d06fcad1529f72ec18ef822a5e50756cc29dbfe74f
[root@docker-136 ~]# docker ps -a    
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                                      NAMES
df9af7f7cb15        kod:v1              "/usr/sbin/init"    43 seconds ago      Up 36 seconds       22/tcp, 0.0.0.0:1080->80/tcp               kod-2
0fd3f853ea4b        centos              "/usr/sbin/init"    37 minutes ago      Up 37 minutes       0.0.0.0:80->80/tcp, 0.0.0.0:1022->22/tcp   kod-1
[root@docker-136 ~]# docker exec -it kod-2 /bin/bash         
#需要手动启动Nginx和php-fpm
[root@df9af7f7cb15 /]# systemctl start nginx
[root@df9af7f7cb15 /]# systemctl start php-fpm
[root@df9af7f7cb15 /]#

 

 

 

 

2  dockerfile自动构建

2.1  dockerfile和文件

[root@docker-136 kod]# pwd
/opt/dockerfile/kod
[root@docker-136 kod]# ls
dockerfile  init.sh  nginx.conf
[root@docker-136 kod]#
[root@docker-136 kod]# cat dockerfile 
FROM  centos
ENV container docker
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
RUN sed -i 's#$releasever#7#g' /etc/yum.repos.d/CentOS-Base.repo
RUN sed -i 's#$basearch#x86_64#g' /etc/yum.repos.d/CentOS-Base.repo
RUN curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
RUN yum install curl  nginx net-tools php-cli php-fpm unzip php-gd php-mbstring -y
RUN sed -i "s#apache#nginx#g"  /etc/php-fpm.d/www.conf
RUN rm -f /etc/nginx/nginx.conf
ADD nginx.conf /etc/nginx/nginx.conf
RUN cd /usr/share/nginx/html  && \curl -o kodexplorer.zip http://static.kodcloud.com/update/download/kodexplorer4.37.zip && \unzip kodexplorer.zip

RUN chown -R nginx:nginx  /usr/share/nginx/html/
ADD init.sh /init.sh

CMD ["/bin/bash","/init.sh"]
[root@docker-136 kod]# cat init.sh 
#!/bin/bash
php-fpm -D 
nginx -g 'daemon off;'
[root@docker-136 kod]# cat nginx.conf 
worker_processes  1;
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   html;
            index index.php index.html index.htm;
        }
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}

 

2.2 提交镜像

docker build -t kod:v8 .

 

2.3 运行镜像

docker run --privileged=true -d  -p 80:80  --name kod-dockerfile-1  kod:v8

 

2.4 测试镜像

 

[root@docker-136 kod]# docker ps -a            
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                NAMES
e531705e9b08        kod:v8              "/bin/bash /init.sh"   22 minutes ago      Up 22 minutes       0.0.0.0:80->80/tcp   kod-dockerfile-1
[root@docker-136 kod]#
[root@docker-136 kod]# docker exec -it  kod-dockerfile-1 /bin/bash 
[root@e531705e9b08 /]# ps -ef       
UID         PID   PPID  C STIME TTY          TIME CMD
root          1      0  0 08:06 ?        00:00:00 /bin/bash /init.sh
root          7      1  0 08:06 ?        00:00:00 php-fpm: master process (/etc/php-fpm.conf)
nginx         8      7  0 08:06 ?        00:00:00 php-fpm: pool www
nginx         9      7  0 08:06 ?        00:00:00 php-fpm: pool www
nginx        10      7  0 08:06 ?        00:00:01 php-fpm: pool www
nginx        11      7  0 08:06 ?        00:00:00 php-fpm: pool www
nginx        12      7  0 08:06 ?        00:00:00 php-fpm: pool www
root         13      1  0 08:06 ?        00:00:00 nginx: master process nginx -g daemon off;
nginx        14     13  0 08:06 ?        00:00:00 nginx: worker process
nginx        30      7  0 08:07 ?        00:00:00 php-fpm: pool www
root         31      0  1 08:10 pts/0    00:00:00 /bin/bash
root         44     31  0 08:10 pts/0    00:00:00 ps -ef
[root@e531705e9b08 /]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      13/nginx: master pr 
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      7/php-fpm: master p 
[root@e531705e9b08 /]#

 

posted on 2019-08-12 16:31  光阴8023  阅读(3614)  评论(0编辑  收藏  举报