版本
- linux:centos6.7
- nginx:13.x
- mysql 未安装 使用其他容器的mysql代替
- php :php7.x
DockerFile
FROM registry.cn-hangzhou.aliyuncs.com/wxopen/lnmp:v3
MAINTAINER q1l1n
#项目路径
COPY . /web/www
# 用编辑过的nginx.conf替换默认的配置文件
COPY ./saas.conf /web/conf
#日志文件夹
RUN mkdir -p /web/saas/log/
#添加权限
RUN chmod -R 777 /web/www
构建镜像过程
拉取镜像
- root#docker pull centos:centos6.7
启动镜像
- root#docker run -i -t centos:centos6.7
查询运行中的容器
- root#docker ps
- 查询到CONTAINER ID 为 x0x0xxx000
进入容器
- root#docker exec -it x0x0xxx000 /bin/sh
centos系统中,如果/sbin目录下没有service这个命令
- yum install initscripts
安装PHP
安装软件包
- CentOs 6.x
- rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
- yum install php70w
- yum install php70w-fpm
安装php 扩展 其他需要可另行安装
- yum install php70w-tidy php70w-common php70w-devel php70w-fpm php70w-mysql
启动php
- service php-fpm start
设置开机启动
- chkconfig --levels 235 php-fpm on
安装nginx
使用第三方源
- wget http://www.atomicorp.com/installers/atomic
- sh ./atomic
- yum check-update
- yum install nginx
启动nginx
- service nginx start
设置开机启动
- chkconfig --levels 235 nginx on
配置nginx 连接php (saas.conf内容)
server {
listen 80;
server_name xxx.xxx.com; #自行定义域名
root /web/www/;
location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php$is_args$args;
if (!-f $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
构建镜像
需要退出镜像到宿主机
- 快捷键 ctrl+p+q
查询容器
- docker ps -lq //查询 ID
- CONTAINER ID为:fe77b1628688
构建命令
docker commit ID为:fe77b1628688 test/lnmp:v1
启动镜像
- docker run -d -p 80:80 -v /web:/www vckai/dev:v1 /sbin/init
- -d是以Daemon模式运行。
- -p 80:80 是将本地80端口映射到容器的80端口,现在可以在本地使用http://localhost访问。
- -v /web:/www 是将本地的/web目录挂载到容器的/www(容器配置的web目录)目录下 。
- vckai/dev:v1 是要运行的镜像名称。
- /sbin/init 是容器运行后的系统初始化操作,主要用于启动nginx,php-fpm,mys> ql服务。
构建完成
将镜像推送到registry(摘抄于阿里云推送镜像):
- $ sudo docker login --username=xxx@xx.com registry.cn-hangzhou.aliyuncs.com
- $ sudo docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/xxx/lnmp:[镜像版本号]
- $ sudo docker push registry.cn-hangzhou.aliyuncs.com/xxx/lnmp:[镜像版本号]
其中[ImageId],[镜像版本号]请你根据自己的镜像信息进行填写。
网友评论