dockerfile編寫項目

項目一:dockerfile編寫可道雲

[root@docker01 kode]# ll
total 13596
-rw-r--r-- 1 root root      320 May 27 17:26 default.conf
-rw-r--r-- 1 root root      392 May 27 17:18 dockerfile
-rwxr-xr-x 1 root root       80 May 27 17:49 init.sh
-rw-r--r-- 1 root root 13894810 May 27 17:16 kodexplorer4.40.zip
-rw-r--r-- 1 root root    10016 May 27 17:15 www.conf
[root@docker01 kode]#

dockerfile 的附件
1、dockerfile內容

[root@docker01 kode]# cat dockerfile
FROM  centos6.9_nginx_ssh:v3
RUN  yum install -y  php-fpm  php-gd php-mbstring
ADD  www.conf  /etc/php-fpm.d/www.conf
ADD  default.conf /etc/nginx/conf.d/default.conf
RUN  mkdir /code
WORKDIR  /code
ADD  kodexplorer4.40.zip .
RUN  yum install -y   unzip
RUN  unzip kodexplorer4.40.zip
RUN  chown -R nginx.nginx .
ADD  init.sh  /init.sh
EXPOSE 80
VOLUME  /code
CMD  ["/bin/bash","/init.sh"]

2、default.conf 配置文件內容

server {
    listen 80;
    server_name localhost;
    root /code;
    location / {
        index index.php index.html index.htm;
    }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
    }
}

3、init.sh腳本信息

[root@docker01 kode]# cat init.sh
#!/bin/bash
/usr/sbin/sshd
/etc/init.d/php-fpm start
nginx -g "daemon off;"

4、www.conf php修改後的配置文件

[root@docker01 kode]# cat www.conf |grep nginx
user = nginx
group = nginx

項目二:dockerfile基於centos7系統構建WordPress

FROM centos:7
RUN curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
RUN yum install nginx mariadb-server php-fpm php-mysql -y
RUN mysql_install_db --user=mysql --defaults-file=/etc/my.cnf
RUN tmp=`nohup mysqld_safe --defaults-file=/etc/my.cnf &` && sleep 5 && \
 mysql -e "create database wordpress;" && \
 mysql -e "grant all on wordpress.* to wordpress@localhost identified by '123456';"


ADD www.conf /etc/php-fpm.d/www.conf

ADD nginx.conf /etc/nginx/nginx.conf

RUN  mkdir /code
WORKDIR /code/
ADD wordpress-4.9.4-zh_CN.zip .
RUN yum install unzip -y

RUN  unzip wordpress-4.9.4-zh_CN.zip
RUN  mv wordpress/* .
RUN  chown -R nginx:nginx .

ADD init.sh /init.sh

CMD ["/bin/bash","/init.sh"]

項目三:dockerfile基於centos6.9系統構建WordPress

FROM centos:6.9
RUN  curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
RUN  curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
RUN  yum install -y  mysql-server
RUN /etc/init.d/mysqld  start && /usr/bin/mysql -e "create database word;" && /usr/bin/mysql -e "grant all on word.* to 'word'@'localhost' identified by '123456';"
RUN  yum install -y nginx
RUN yum install -y  php-fpm  php-gd php-mbstring  php-mysql
COPY  www.conf /etc/php-fpm.d/www.conf
RUN /etc/init.d/php-fpm start
COPY  default.conf /etc/nginx/conf.d/default.conf
RUN  mkdir /word
COPY wordpress-4.8.13.zip /word
RUN  yum install -y  unzip
WORKDIR /word
RUN  unzip wordpress-4.8.13.zip
RUN  mv wordpress/* ./
RUN  chown  nginx.nginx  -R /word
EXPOSE 80
COPY  init.sh /init.sh
RUN chmod  a+x /init.sh
CMD  source /init.sh

腳本信息

[root@docker01 word]# cat init.sh
#!/bin/bash
/etc/init.d/mysqld  start
/etc/init.d/php-fpm start
nginx -g "daemon off;"
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章