在WSL中使用docker独立运行lnmp
在WSL中使用docker独立运行lnmp
温馨提示:wsl中的docker需要管理员权限运行才可以启动。
nginx and php
使用docker下拉运行nginx和php-fpm两个容器时,需要将这两个容器的目录/usr/share/nginx/html/映射到自定义Web根目录(例如mkdir -p /var/www/html)进行关联,接着配置/etc/nginx/conf.d/default.conf文件,下面是我的配置文件
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
#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 html;
fastcgi_pass 172.17.0.3:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $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;
#}
}
当运行mysql容器时会出现错误而无法正常运行,这里怀疑是权限问题,需要进入到容器里进行初始化,然后指定root用户启动数据库,接着从另起一个终端进入(感觉有点类似C/S模式,并且很不安全),经过尝试成功运行了mysql容器。
mysql
#first bash
[email protected]:/home/jie# docker exec -it mysql bash
[email protected]:/# mysqld --initialize-insecure
[email protected]:/# mysqld --user=root
#two bash
[email protected]:/# mysql
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
mysql> flush privileges;
以下资源地址:
[1]: https://docs.docker.com/install/linux/docker-ce/ubuntu/
[2]: https://www.jianshu.com/p/aeaa851b0721
[3]: https://mirrors.aliyun.com/ubuntu/