需要的网站如下:
Docker Hub: https://hub.docker.com/
Docker Cloud: https://cloud.docker.com
github: https://github.com/
这篇博客只是一次docker 镜像的自动构建,关于Dockerfile的编写,上下文路径等请提前学习.
pagekit CMS: 开源的php内容管理系统
环境:PHP,Web(Nginx),PHP扩展(php5-fpm php5-cli php5-json php5-mysql php5-curl) 基本服务组件(ca-certificates)
思路: 将编写的文件push到github上的仓库,在docker hub 或docker cloud上设置与github的hook并触发自动构建.
代码下载:git@github.com:xiaer1921/docker_pagekit.git
一.Docker Hub自动构建
1. 配置Docker Hub,右上角头像菜单->Settings->Linked Accounts & Services->Link Github.
2.右上角Create->Create Automated Build->Link Account Github->选择github 仓库
3.创建后Build Settings可以看到Branch选择,就能理解,触发会根据你的设置对你更改的github分支进行自动构建,Build Details可以看到构建历史.Tags查看创建成功的镜像.
二.Docker cloud自动构建
1.Repositories->创建一个仓库,Link to Github后,Builds->Configure Automated Builds->Build Text为上下文路径,Dockerfile location是相对上下文来说的,一定要选Autobuild.
2.Timeline可浏览构建历史和日志.
在自动构建完成以后,docker会给邮箱里发送构建信息.
三.
Dockerfile文件代码:
FROM ubuntu:trusty
RUN apt-get update && \
apt-get -y install \
nginx \
unzip \
wget \
ca-certificates \
php5 php5-fpm php5-cli php5-json php5-mysql php5-curl
ENV PAGEKIT_VERSION 1.0.2
RUN mkdir /pagekit
WORKDIR /pagekit
VOLUME ["/pagekit/storage", "/pagekit/app/cache"]
RUN wget https://github.com/pagekit/pagekit/releases/download /$PAGEKIT_VERSION/pagekit-$PAGEKIT_VERSION.zip -O /pagekit/pagekit.zip && \
unzip /pagekit/pagekit.zip && rm /pagekit/pagekit.zip
ADD /pagekit/nginx.conf /etc/nginx/nginx.conf
RUN chown -R www-data:/pagekit &&\
apt-get autoremove wget unzip -y && \
apt-get autoclean -y && \
apt-get clean -y && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
CMD ["sh", "-c", "service php5-fpm start && nginx"]
Nginx配置文件:
user www-data;
worker_processes 4;
pid /run/nginx.pid;
daemon off;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log ;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
server {
root /pagekit;
location / {
try_files $uri $uri/ /index.php?$args;
index index.html index.htm index.php;
}
location ~ \.php$ {
try_files $uri $uri/ /index.php?$args;
index index.html index.htm index.php;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTP_MOD_REWRITE On;
fastcgi_pass unix:/var/run/ php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
}
}
}
吐槽一句,写博客真的是耗时,想想一本书都看完了,才懒得写了一篇博客,<Docker从入门到实战>与<Kubernetes权威指南从Docker到Kubernetes实践全接触>相比,完全是小巫见大巫,慢慢来吧.