docker 搭建LNMP网站平台
准备好镜像
1、创建网络
docker network create lnmp
测试环境需删除全部之前起的容器
docker rm -f $(docker ps -a |awk '{print $1}'|sed '1d')
2、创建MySQL容器
docker run -d --restart=always \ --name lnmp_mysql \ --net lnmp \ --mount src=mysql-vol,dst=/var/lib/mysql \ -e MYSQL_ROOT_PASSWORD=123456 \ -e MYSQL_DATABASE=wordpress mysql:5.7 --character-set-server=utf8 ls /var/lib/docker/volumes/mysql-vol/_data/
3、创建PHP容器
docker run -d \ --restart=always \ --name lnmp_php \ --net lnmp \ --mount src=wwwroot,dst=/wwwroot php:v1
4、创建nginx容器
编写nginx.conf文件
user nobody; worker_processes 4; worker_rlimit_nofile 65535; error_log logs/error.log notice; pid /var/run/nginx.pid; events { use epoll; worker_connections 4096; } 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 off; keepalive_timeout 65; client_max_body_size 64m; server { listen 80; server_name www.abc.com; index index.php index.html; access_log logs/www.abc.com_access.log; error_log logs/www.abc.com_error.log; # location ~ .*\.(js|css|html|png|gif|jpg|jpeg)$ { location / { root /wwwroot; } location ~* \.php$ { root /wwwroot; fastcgi_pass lnmp_php:9000; #需要自定义网络地址通过DNS解析 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } }
运行nginx容器
docker volume create nginx-vol docker run -d \ --name lnmp_nginx \ --net lnmp -p 8000:80 \ --mount type=bind,src=$(pwd)/nginx.conf,dst=/usr/local/nginx/conf/nginx.conf \ --mount src=wwwroot,dst=/wwwroot nginx:v1
进入被容器挂载的目录创建测试文件
cd /var/lib/docker/volumes/wwwroot/_data/
echo " <?php phpinfo();?>" >/var/lib/docker/volumes/wwwroot/_data/test.php
5、以wordpress博客为例
下载地址:https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
cd /var/lib/docker/volumes/wwwroot/_data
wget -q https://cn.wordpress.org/wordpress-5.0.3-zh_CN.tar.gz
tar xf wordpress-5.0.3-zh_CN.tar.gz
使劲折腾才会有更好的结果!!!!
如有不对请不吝赐教,感谢!
转载请注明出处!