Dockfile定制docker镜像

本文介绍了一个具体的Dockerfile实例,展示了如何从CentOS基础镜像出发,安装必要的软件和服务(如PHP、Nginx),并配置运行环境来部署showdoc应用。

Dockerfile构建镜像是以基础镜像为基础的,Dockerfile是一个文本文件,内容是用户编写的一些docker指令,每一条指令构建一层,因此每一条指令的内容,就是描述该层应当如何构建。

Dockerfile的基本指令有十三个,分别是:FROM、MAINTAINER、RUN、CMD、EXPOSE、ENV、ADD、COPY、ENTRYPOINT、VOLUME、USER、WORKDIR、ONBUILD

准备:下载安装包,注意,以下的操作必须在showdoc目录下。

mkdir -p showdoc
cd showdoc
wget https://github.com/star7th/showdoc/archive/master.zip

 准备 showdoc.conf文件

root@sv10-141 showdoc]#  tee showdoc.conf <<EOF

    server {
    listen       80 default_server;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm index.php;

       # proxy_pass http://lanlan;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
  location ~ \.php$ {
         root           /usr/share/nginx/html;
         fastcgi_pass   php-fpm;
         fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
         include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
}
EOF

准备nginx文件 

tee nginx.conf <<EOF
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
server {
        listen       80 ;
        listen       [::]:80 default_server;
        server_name  showdoc;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
}
EOF

 准备Dockerfile

[root@sv10-141 showdoc]# cat  <<EOF >Dockerfile
FROM centos
MAINTAINER  yanfeng rudolfyan@qq.com
WORKDIR /opt
RUN  yum install php-zip nginx unzip php-json php-gd php-pdo php-mbstring php-fpm  php  -y
COPY master.zip .
RUN unzip  -q master.zip && mv showdoc-master /usr/share/nginx/html/showdoc&& rm -f /usr/share/nginx/html/showdoc/install/install.lock && chmod -R 777  /usr/share/nginx/html/showdoc
COPY nginx.conf /etc/nginx/nginx.conf
COPY showdoc.conf /etc/nginx/conf.d
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
RUN echo "mkdir -p /run/php-fpm && touch /run/php-fpm/www.sock && chmod 777 /run/php-fpm/www.sock && nginx  && php-fpm --nodaemonize " > cmd.sh && chmod 755 cmd.sh
EXPOSE 80
CMD /opt/cmd.sh
EOF

执行buid

docker build . -t rudolfyan/showdoc:v1

上传

docker login
....
docker push rudolfyan/showdoc:v1

完成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

老骥又出发

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值