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
完成

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

被折叠的 条评论
为什么被折叠?



