One: Install docker and docker-compose

For the specific installation method, please refer to the data installation by yourself, and I will not go into details here.

Two: Download the mysql-nginx-php image and install some basic software and extensions

1: Download the mysql image

 docker pull mysql:5.7

2: Download the nginx image

 docker pull nginx:1.21.6

3: Download the php image

 docker pull php:7.2-fpm

4: Install extensions and basic software for the php basic image

 docker run -it --name php php:7.2-fpm /bin/bash

Use docker run to run the image and enter the image and do the following

 #apt-get 更新
apt-get update
#基础依赖安装
apt-get update && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libmcrypt-dev libpng-dev
#安装wget
apt-get install wget
#安装定时器crontab
apt-get install cron
#安装supervisor进程管理
apt-get install supervisor
#安装php拓展
cd ~
wget https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions
mv install-php-extensions /usr/local/bin
chmod uga+x /usr/local/bin/install-php-extensions && sync
install-php-extensions 拓展名(bcmath,decimal,exif,gd,imagick,intl,memcached,mongodb,pcntl,pdo_mysql,pdo_pgsql,soap,swoole,zip)
#增加一个www用户
adduser www

5: Save the processed container as an image

 docker commit php php:7.2(将php容器保存为php:7.2镜像)

I have processed the image here and uploaded it to my docker repository, and I can directly pull the image in my own repository for subsequent use.

Three: Use docker-compose to configure the php environment based on the nginx-mysql-php image

1: For the specific docker-compose file content, please refer to:

docker-compose configuration

2: Run the container using the docker-compose command

 docker-compose build --force-rm(构建容器并删除构建过程中创建的临时容器)
docker-compose up -d(在后台运行容器)
docker-compose start(启动容器)
docker-compose stop(停止正在预先的容器)
docker-compose down(删除容器)
docker-compose run --rm -u www --entrypoint='' php bash(以www用户运行php容器并进入容器,进入容器后删除容器)

huaweichenai
673 声望114 粉丝

« 上一篇
docker常用命令
下一篇 »
Git常用命令