最近忙着写自己的项目,也把一个站点的bbs论坛打算迁移到Docker中,测试没发现啥大问题。在单台上面的架构如下;(往后我们也是要讲到compose和swarm调度的慢慢来)
1、首先我们先安装一下docker,好多人都发现国内用yum安装有各种问题;这里我们用国内的https://www.daocloud.io.登录后注册,然后点击下载。里面有提示,我们点击Linxu安装然后复制代码执行到shell上即可。
[root@test nginx]# curl -sSL https://get.daocloud.io/docker | sh
2、安装好之后,安装dockhub加速器,点击加速器,复制代码粘贴到shell.
[root@test nginx]# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s
{"registry-mirrors": ["http://681a96df.m.daocloud.io"],
"live-restore": true
}
Success.
You need to restart docker to take effect: sudo systemctl restart docker
##执行脚本,主要是把仓库地址写到daemon.json文件下。
[root@test nginx]# cat /etc/docker/daemon.json
{"registry-mirrors": ["http://681a96df.m.daocloud.io"],
"live-restore": true
}
3、准备工作都已经完成了,接下来我们来构建一下dockerfile在三个目录下,看下目录结构:
[root@test test]# tree -L 2 --charset ASCII
|-- MySQL
| |-- Dockerfile
| |-- epel-6.repo
| |-- my.cnf
| `-- startup.sh
|-- nginx
| |-- Dockerfile
| |-- nginx-1.11.10
| |-- nginx-1.11.10.tar.gz
| |-- nginx.conf
| `-- nginx_default.conf
`-- php-fpm
|-- CentOS-6.repo
|-- Dockerfile
|-- epel-6.repo
|-- php-5.5.38
`-- php-5.5.38.tar.gz
5、看一下nginx 的 Dockerfile:
[root@test nginx]# cat Dockerfile
#lnmp centos 6.0
from centos:centos6
MAINTAINER xiaoluo <xiaoluo@test.com>
ENV APP_DIR /web
add nginx-1.11.10 /nginx-1.11.10
RUN yum -y groupinstall "Development Tools" "Server Platform Deveopment"
RUN yum -y install openssl-devel pcre-devel
RUN useradd nginx -s /sbin/nologin
RUN cd /nginx-1.11.10 && ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre && make && make install
RUN mkdir /usr/local/nginx/conf/vhosts
RUN mkdir /var/log/nginx
ADD nginx.conf /usr/local/nginx/conf/nginx.conf
ADD nginx_default.conf /usr/local/nginx/conf/vhosts/default.conf
EXPOSE 80
CMD ["/usr/local/nginx/sbin/nginx"]
##nginx 相关php配置:
[root@test nginx]# cat nginx_default.conf
server {
listen 80 default_server;
server_name localhost;
#charset koi8-r;
location / {
root /web;
index index.php index.html index.htm;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root APP_DIR;
}
# Disable nginx log write favicon.ico
location = /favicon.ico {
log_not_found off;
access_log off;
}
# pass the PHP scripts to FastCGI server listening on port 9000
#
location ~ \.php$ {
root /web;
fastcgi_pass php:9000;
#fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
###php:9000是通过后面的--link 容器之间互联指定
6、开始构建nginx镜像:
[root@test nginx]# docker build -t lnmp/nginx:1.0 .
##查看是否生成镜像:
[root@test nginx]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
lnmp/nginx 1.0 5f5d4169189d 4 minutes ago 669 MB
7、开始构建php镜像: