https://gitee.com/wangxuancheng/lnmp/tree/master
拉取镜像
docker network create web
docker pull mysql:5.7
docker pull nginx:latest
docker pull php:7.4-fpm
docker pull redis:latest
docker pull memcached:1.5.16
docker pull phpmyadmin/phpmyadmin
运行容器
docker run --name my_mysql -d --network web -p 3306:3306 \
-v /wwwroot/mysql/conf.d:/etc/mysql/conf.d \
-v /wwwroot/mysql/log:/var/log/mysql \
-v /wwwroot/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=12345678 mysql:5.7
docker run -dit --network web -p 80:80 -p 443:443 \
-v /wwwroot/nginx/log:/var/logs/nginx \
-v /wwwroot/nginx/conf.d:/etc/nginx/conf.d \
-v /wwwroot/nginx/html:/usr/share/nginx/html \
--name my_nginx nginx:latest
docker run -p 9000:9000 --network web --name my_php \
-v /wwwroot/nginx/html:/var/www/html \
-v /wwwroot/php/conf:/usr/local/etc/php \
-v /wwwroot/php/conf/conf.d:/usr/local/etc/php/conf.d \
-d php:7.4-fpm
docker run --name my_redis -d --network web -p 6379:6379 \
-v /wwwroot/redis/redis.conf:/usr/local/etc/redis/redis.conf \
-v /wwwroot/redis/data:/data \
redis:latest redis-server --appendonly yes
docker run --name my_memcache -p 11211:11211 -d memcached:1.5.16
docker run --name my_phpmyadmin --network web \
-d -p 888:80 --restart=always -e PMA_ARBITRARY=1 \
-v /wwwroot/phpmyadmin/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php \
-v /wwwroot/phpmyadmin/php.ini:/usr/local/etc/php/conf.d/php.ini \
phpmyadmin/phpmyadmin
容器内vim安装
apt-get update
apt-get install vim
配置mysql
进入容器
docker exec -it mysql容器id bash
登录mysql
mysql -u root -p
修改root密码 password新密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
添加远程登录用户 如 user1:123456
CREATE USER 'user1'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
GRANT ALL PRIVILEGES ON *.* TO 'user1'@'%';
退出
quit
exit
配置nginx
cd /wwwroot/nginx/conf.d
vim default.conf
server {
listen 80;
#listen 443 ssl;
server_name localhost;
root /usr/share/nginx/html;
index index.php index.html index.htm;
#ssl on;
#ssl_certificate /localhost.crt;
#ssl_certificate_key /localhost.key;
#ssl_session_timeout 5m;
#ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
#ssl_prefer_server_ciphers on;
access_log /var/logs/nginx/localhost.access.log;
error_log /var/logs/nginx/localhost.error.log;
#强制https
if ($scheme != "https") {
#return 301 https://$host$request_uri;
}
location / {
}
location ~ \.php$ {
root /var/www/html;
fastcgi_pass my_php:9000; #容器名称或者容器ip
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
php扩展安装 (扩展目录 /usr/local/etc/php/conf.d )
docker exec -it php容器id bash
docker-php-ext-install bcmath
docker-php-ext-install redis
docker-php-ext-install opcache
docker-php-ext-install sockets
docker-php-ext-install exif
docker-php-ext-install pcntl
docker-php-ext-install gd
docker-php-ext-install memcached
pecl install swoole && docker-php-ext-enable swoole
apt install libzip-dev
docker-php-ext-install zip
apt-get -y install libmcrypt-dev
pecl install mcrypt-1.0.3
cd /usr/local/etc/php/conf.d
vim docker-php-ext-mcrypt.ini
extension=mcrypt.so
apt-get update
apt-get install wget
wget --version
wget http://pecl.php.net/get/imagick-3.4.3.tgz
tar -xzvf imagick-3.4.3.tgz
cd imagick-3.4.3
/usr/local/bin/phpize
./configure --with-php-config=/usr/local/bin/php-config
apt-get install libmagickwand-dev libmagickcore-dev
pecl install imagick && docker-php-ext-enable imagick
wget https://github.com/websupport-sk/pecl-memcache/archive/NON_BLOCKING_IO_php7.zip
apt-get install unzip
unzip NON_BLOCKING_IO_php7.zip
cd pecl-memcache-NON_BLOCKING_IO_php7/
/usr/local/bin/phpize
./configure --with-php-config=/usr/local/bin/php-config
make && make install
docker-php-ext-enable memcache
打包镜像
docker commit c597a3f84a3a wxc/mysql:5.7
docker commit c597a3f84a3a wxc/php:7.4
docker commit c597a3f84a3a wxc/nginx:1.17.9
docker commit c597a3f84a3a wxc/memcached:1.5.16
docker commit c597a3f84a3a wxc/redis:5.0.8
docker commit c597a3f84a3a wxc/phpmyadmin:5.0.2
我的镜像
sudo docker pull registry.cn-hangzhou.aliyuncs.com/wangxuancheng/nginx:1.17.9
sudo docker pull registry.cn-hangzhou.aliyuncs.com/wangxuancheng/php:7.4
sudo docker pull registry.cn-hangzhou.aliyuncs.com/wangxuancheng/mysql:5.7
sudo docker pull registry.cn-hangzhou.aliyuncs.com/wangxuancheng/redis:5.0.8
sudo docker pull registry.cn-hangzhou.aliyuncs.com/wangxuancheng/phpmyadmin:5.0.2
网友评论