Docker Compose 一键部署LNMP

目录结构

[root@localhost ~]# tree compose_lnmp/
compose_lnmp/
├── docker-compose.yml
├── mysql
│ ├── conf
│ │ └── my.cnf
│ └── data
├── nginx
│ ├── Dockerfile
│ ├── nginx-1.12.1.tar.gz
│ └── nginx.conf
├── php
│ ├── Dockerfile
│ ├── php-5.6.31.tar.gz
│ └── php.ini
└── wwwroot
└── test.php

一、创建Nginx Compose

1.1、创建compose目录作为LNMP的项目管理目录

mkdir compose_lnmp
cd compose_lnmp/

1.2、创建nginx管理目录

mkdir nginx
cd nginx

1.3、将nginx源码包下载到本地

  • Nginx-1.12.1
  • 下载地址:https://pan.baidu.com/s/1IAdODW63jbpwbQX992coYg
  • 密码:p89j

1.4、创建Dockerfile文件

vim Dockerfile

# 指定镜像
FROM centos:6
# 指定管理员
MAINTAINER xiangsikai
# 执行命令安装编译库文件
RUN yum install -y gcc gcc-c++ make openssl-devel pcre-devel
# 添加解压nginx包到/tmp目录下
ADD nginx-1.12.1.tar.gz /tmp
# 进入目录进行编译安装
RUN cd /tmp/nginx-1.12.1 && ./configure --prefix=/usr/local/nginx && make -j 2 && make install
# 删除容器内置配置文件
RUN rm -f /usr/local/nginx/conf/nginx.conf
# 复制本地配置文件到容器内
COPY nginx.conf /usr/local/nginx/conf
# 声明暴露端口
EXPOSE 80
# 启动容器Nginx服务,指定全局命令daemon off保证服务在前台运行不会关闭
CMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;"]

1.5、创建nginx.conf配置文件

vim nginx.conf

user  root;
worker_processes auto; error_log logs/error.log info; pid logs/nginx.pid; events {
use epoll;
} http { include mime.types;
default_type application/octet-stream; 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 logs/access.log main;
sendfile on;
keepalive_timeout 65; server {
listen 80;
server_name localhost;
root html;
index index.html index.php; location ~ \.php$ {
root html;
fastcgi_pass php-cgi:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}

nginx配置文件


二、创建Mysql Compose

2.1、创建Mysql管理目录

mkdir mysql
cd mysql
mkdir conf
cd conf

2.2、创建mysql配置文件

vim my.cnf

[mysqld]
user=mysql
port=3306
datadir=/var/lib/mysql
socket=/var/run/mysqld/mysqld.sock
pid-file=/var/run/mysqld/mysqld.pid
log_error=/var/log/mysql/error.log
character_set_server = utf8
max_connections=3600

mysql配置文件


三、创建PHP Compose

3.1、创建Mysql管理目录

mkdir php
cd php

3.2、下载php源码包

  • php-5.6.31
  • 下载地址:https://pan.baidu.com/s/17cC8Ad9h4llMb7JC57N1GQ
  • 密码:wl2w

3.3、创建Dockerfile文件

vim Dockerfile

# 指定镜像
FROM centos:6
# 指定系统管理员
MAINTAINER xiangsikai
# 安装编译库
RUN yum install -y gcc gcc-c++ gd-devel libxml2-devel libcurl-devel libjpeg-devel libpng-devel openssl-devel
# 下载压缩包解压到指定目录
ADD php-5.6.31.tar.gz /tmp/
# 编译安装php,执行相关命令
RUN cd /tmp/php-5.6.31 && \
./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-mysql --with-mysqli \
--with-openssl --with-zlib --with-curl --with-gd \
--with-jpeg-dir --with-png-dir --with-iconv \
--enable-fpm --enable-zip --enable-mbstring && \
make -j 4 && make install && \
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf && \
sed -i "s/127.0.0.1/0.0.0.0/" /usr/local/php/etc/php-fpm.conf && \
cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm && \
chmod +x /etc/init.d/php-fpm
# 复制本地配置文件到容器内
COPY php.ini /usr/local/php/etc
# 声明暴露端口
EXPOSE 9000
# 启动php
CMD /etc/init.d/php-fpm start && tail -F /var/log/messages

3.4、创建php.ini文件

vim php.ini

[PHP]
engine = On
short_open_tag = Off
asp_tags = Off
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = 17
disable_functions =
disable_classes =
zend.enable_gc = On
expose_php = On
max_execution_time = 30
max_input_time = 60
memory_limit = 128M
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
html_errors = On
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 8M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
doc_root =
user_dir =
enable_dl = Off
file_uploads = On
upload_max_filesize = 2M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
[CLI Server]
cli_server.color = On
[Date]
date.timezone = Asia/Shanghai
[filter]
[iconv]
[intl]
[sqlite]
[sqlite3]
[Pcre]
[Pdo]
[Pdo_mysql]
pdo_mysql.cache_size = 2000
pdo_mysql.default_socket=
[Phar]
[mail function]
SMTP = localhost
smtp_port = 25
sendmail_path = /usr/sbin/sendmail -t -i
mail.add_x_header = On
[SQL]
sql.safe_mode = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[Interbase]
ibase.allow_persistent = 1
ibase.max_persistent = -1
ibase.max_links = -1
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
ibase.dateformat = "%Y-%m-%d"
ibase.timeformat = "%H:%M:%S"
[MySQL]
mysql.allow_local_infile = On
mysql.allow_persistent = On
mysql.cache_size = 2000
mysql.max_persistent = -1
mysql.max_links = -1
mysql.default_port =
mysql.default_socket =
mysql.default_host =
mysql.default_user =
mysql.default_password =
mysql.connect_timeout = 60
mysql.trace_mode = Off
[MySQLi]
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.cache_size = 2000
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = Off
[OCI8]
[PostgreSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[Sybase-CT]
sybct.allow_persistent = On
sybct.max_persistent = -1
sybct.max_links = -1
sybct.min_server_severity = 10
sybct.min_client_severity = 10
[bcmath]
bcmath.scale = 0
[browscap]
[Session]
session.save_handler = files
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.bug_compat_42 = Off
session.bug_compat_warn = Off
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
[MSSQL]
mssql.allow_persistent = On
mssql.max_persistent = -1
mssql.max_links = -1
mssql.min_error_severity = 10
mssql.min_message_severity = 10
mssql.compatability_mode = Off
mssql.secure_connection = Off
[Assertion]
[mbstring]
[gd]
[exif]
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
[sysvshm]
[ldap]
ldap.max_links = -1
[mcrypt]
[dba]

php配置文件


四、创建DockerCompose文件

4.1 进入compose_lnmp目录下创建DockerCompose文件

[root@localhost compose_lnmp]# ls
mysql nginx php

vim docker-compose.yml

# 指定服务版本号
version: ''
# 服务
services:
# 服务名称
nginx:
# 指定服务容器名字
hostname: nginx
# 构建
build:
# 指定目录上下文构建镜像
context: ./nginx
# 指定dockerfile文件名称
dockerfile: Dockerfile
# 映射数组级的端口
ports:
- "80:80"
# 映射php文件服务别名
links:
- "php:php-cgi"
# 映射服务数据卷路径
volumes:
- ./wwwroot:/usr/local/nginx/html # 服务名称
php:
# 指定服务容器名字
hostname: php
# 构建
build: ./php
# 映射mysql服务别名
links:
- mysql:mysql-db
# 映射服务数据卷路径
volumes:
- ./wwwroot:/usr/local/nginx/html # 服务名称
mysql:
# 指定服务容器名字
hostname: mysql
# 指定使用官方mysql5.6版本
image: mysql:5.6
# 映射端口
ports:
- "3306:3306"
# 映射服务数据卷路径
volumes:
- ./mysql/conf:/etc/mysql/conf.d
- ./mysql/data:/var/lib/mysql
# 指定数据库变量
environment:
# 设置数据库密码
MYSQL_ROOT_PASSWORD: 123456
# 添加user用户
MYSQL_USER: user
# 设置user用户密码
MYSQL_PASSWORD: user123

4.2、执行docker Compose一键部署LNMP

# 需要在yml文件同级目录下执行此命令
docker-compose up

4.3、进入网站目录创建php测试页并进行测试

cd wwwroot/
vim test.php
#-----------------
<?php phpinfo()?>
#-----------------

4.4、测试:192.168.1.77/test.php

注:执行docker-compose up之前需要关闭SELINUX。博主踩的坑。

Docker Compose 一键部署LNMP的更多相关文章

  1. Docker Compose 一键部署Nginx代理Tomcat集群

    Docker Compose 一键部署Nginx代理Tomcat集群 目录结构 [root@localhost ~]# tree compose_nginx_tomcat/ compose_nginx ...

  2. Docker Compose 一键部署多节点爬虫程序

    Docker Compose 一键部署多节点爬虫程序 目录结构 [root@localhost ~]# tree compose_crawler/ compose_crawler/ ├── cento ...

  3. 开源跨境ERP - 小老板 Docker/Docker Compose一键部署

    先上部署成功后的截图,各个菜单点击均无报错 DockerCompose 包含: 1. 三个mysql5.7数据库 2. redis php会话存储+ memcached 3. 小老板php主程序 do ...

  4. [Docker]compose一键部署nginx

    Docker-compose部署nginx 创建配置文件 mkdir -p /usr/local/docker/nginx cat > /usr/local/docker/nginx/docke ...

  5. Docker Compose一键部署Nginx反向代理Tomcat集群

    目录结构如下 mysql/conf/my.cnf [mysqld] user=mysql port=3306 datadir=/var/lib/mysql socket=/var/lib/mysql/ ...

  6. 【shell脚本】一键部署LNMP===deploy.sh

    一键部署mysql,php,nginx,通过源码安装部署 #!/bin/bash # 一键部署 LNMP(源码安装版本) menu() { clear echo " ############ ...

  7. 一键部署lnmp

      一键部署lnmp 提前将nginx .mysql .php  所需安装包都放在/opt目录下 脚本启动结束时,重启一下nginx 服务,就能在火狐浏览器更新出php测试页 脚本如下:(脚本里的软件 ...

  8. 使用Docker 一键部署 LNMP+Redis 环境

    使用Docker 部署 LNMP+Redis 环境 Docker 简介 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linu ...

  9. [phvia/dkc] Docker Compose 快速构建(LNMP+Node)运行环境

    快速构建(LNMP+Node)运行环境. dkc 在此作为 docker-compose 的缩写,你可以理解为 alias dkc=docker-compose 准备 安装 docker 选择1) 从 ...

随机推荐

  1. 【Zookeeper系列】ZooKeeper管理分布式环境中的数据(转)

    原文地址:https://www.cnblogs.com/sunddenly/p/4092654.html 引言 本节本来是要介绍ZooKeeper的实现原理,但是ZooKeeper的原理比较复杂,它 ...

  2. MYSQL 内存模型

  3. 如何写Emit代码

    写Emit代码也不是想象中的那么复杂,基本过程就是先手工写好C#代码,编译得到Exe或者Dll,然后用ILDASM或反编译工具,得到IL代码,最后就是看着IL代码,用Emit一个个对应发出代码,就行了 ...

  4. Linux服务器中创建Oracle数据库实例

    紧接上篇,在Linux服务器已经完成对Oracle数据库软件的安装后,接下来要创建Oracle实例,看图说话: [su – oracle echo $DISPLAY export DISPLAY=10 ...

  5. Android Runtime Stats

    Android 在 API 23 增加了运行时 GC 状态的获取接口,用法如下: Map<String, String> map = Debug.getRuntimeStats(); St ...

  6. python根据字符串导入模块

    问题: path = "auth.my_auth.AUTH" # 根据path实例化AUTH类 解决: path = "auth.my_auth.AUTH" i ...

  7. Tensorflow一些常用基本概念与函数(1)

    为了快速的熟悉TensorFlow编程,下面从一段简单的代码开始: import tensorflow as tf #定义‘符号’变量,也称为占位符 a = tf.placeholder(" ...

  8. UML关系实现、泛化,依赖、组合

    图片via<大话设计模式> UML一目了然

  9. MySql的主从复制以及读写分离详解

    MySQL主从复制(Master-Slave)与读写分离(MySQL-Proxy)实践 Mysql作为目前世界上使用最广泛的免费数据库,相信所有从事系统运维的工程师都一定接触过.但在实际的生产环境中, ...

  10. JavaScript基础知识(数组的方法)

    数组的方法(15个) 对象数据类型: 数组成员有一个与之对应的索引 length : 代表数组成员的个数: 操作改变数组一些方法:这些数组的方法都是内置的: // 1. 方法作用: // 2. 方法的 ...