Mac M1 安装Docker
1、Docker下载
docker官网下载m1版本:https://docs.docker.com/docker-for-mac/apple-silicon/点击Download下载.dmg文件。
2、Docker安装
双击下载的Docker.dmg文件开始安装,拖动Docker到Applications等待安装完成。
3、Docker启动
在启动台找到Docker软件图标点击启动,稍等片刻启动成功,屏幕右上角菜单栏显示了一个鲸鱼图标,点击可看到Docker运行状态。
4、增加国内镜像链接
"registry-mirrors": [
"https://xxxxxx.mirror.aliyuncs.com",
"http://hub-mirror.c.163.com"
],
Docker 安装 Nginx
$ docker pull nginx:latest
Docker 安装 PHP
$ docker pull php:7.4.25-fpm
docker配置PHP开发环境(m1mac+nginx+php)
1、创建目录
mkdir -p /Users/jarmin/docker/nginx/conf.d && mkdir /Users/jarmin/WWW && cd /Users/jarmin/docker/nginx/conf.d && sudo touch default.conf
2、启动php-fpm
docker run --name php -d
-v /Users/jarmin/WWW:/var/www/html
php:7.1-fpm
3、编辑 nginx 配置文件
配置文件位置:
/Users/jarmin/docker/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
location / {
index index.php index.html;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
location ~ .php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param script_FILENAME /var/www/html/$fastcgi_script_name;
include fastcgi_params;
}
}
# 绑定域名
server {
listen 80;
server_name www.tp.com;
root /usr/share/nginx/html/tp.com/public;
location / {
index index.php index.html;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
location ~ .php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param script_FILENAME /var/www/html/tp.com/public/$fastcgi_script_name;
include fastcgi_params;
}
}
4、启动 nginx:
docker run --name nginx -p 80:80 -d
-v /Users/jarmin/WWW:/usr/share/nginx/html
-v /Users/jarmin/docker/nginx/conf.d:/etc/nginx/conf.d
--link php:php
nginx
在本地 /Users/jarmin/www 下放两个文件:index.php
Docker为PHP安装gd扩展
//进入PHP容器 $ docker exec -it php /bin/bash //更新软件源 apt update //安装各种库 apt install -y libwebp-dev libjpeg-dev libpng-dev libfreetype6-dev //解压源码 docker-php-source extract //进入gd源码文件夹 cd /usr/src/php/ext/gd //准备编译 docker-php-ext-configure gd --with-webp-dir=/usr/include/webp --with-jpeg-dir=/usr/include --with-png-dir=/usr/include --with-freetype-dir=/usr/include/freetype2 //编译安装 docker-php-ext-install gd //查看是否成功安装gd扩展 php -m | grep gd //重启容器
php容器安装pdo_mysql扩展
//进入PHP容器 $ docker exec -it php /bin/bash //安装pdo_mysql扩展 $ docker-php-ext-install pdo pdo_mysql



