Docker Setup
yum install -y yum-utils device-mapper-persistent-data
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce
配置
systemctl start docker
systemctl enable docker
Mysql
创建容器
docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root --name m_mysql mysql:5.7
进入容器:
docker exec -it m_mysql /bin/bash
- 进入mysql
mysql -uroot -proot
- 选择数据库
use mysql
- 开启远程连接
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
- 重启
docker restart m_mysql
PHP
创建容器
docker run -d -p 9000:9000 -v /data/wwwroot:/usr/share/nginx/html --link m_mysql:mysql --name m_phpfpm bitnami/php-fpm:7.0
进入容器
docker exec -it m_phpfpm /bin/bash
Nginx
创建容器
docker run -d -p 80:80 -v /data/wwwroot:/usr/share/nginx/html -v /data/nginx:/etc/nginx -v /data/wwwlogs:/var/log/nginx --link m_phpfpm:phpfpm --name m_nginx nginx:latest
修改/data/nginx/conf/default.conf,配置如下:
server {
listen 80;
server_name _;
#charset koi8-r;
access_log /var/log/nginx/default_nginx.log main;
location / {
root /usr/share/nginx/html/default;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html/default;
fastcgi_pass phpfpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
参考链接:https://notemi.cn/docker-quickly-set-up-php-nginx-mysql-environment.html
网友评论