When I started my internship in 2018, I built an LNMP development environment. In the course, I built a LAMP development environment for Docker and pulled an integrated LNMP environment. Today, I use mysql, Nginx and PHP images to build phP-FPM environment for multiple containers.

To prepare

  • Docker installation without brain tutorial can refer to docker installation
  • Install the docker – compose
Sudo curl -l https://github.com/docker/compose/releases/download/1.24.0/docker-compose- ` uname-s`-`uname -m` -o /usr/local/bin/docker-compose 

sudo chmod +x /usr/local/bin/docker-compose

docker-compose --version
Copy the code
  • Before pulling the image, let’s set up the Docker accelerator
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://5a88fb64.m.daocloud.io
Copy the code

Docker-comemage.yml is the latest version of docker-comemage.yml. Mysql 5.7 mysql 5.7 mysql 5.7 mysql 5.7 mysql 5.7 mysql 5.7 mysql 5.7

Nginx docker pull PHP :7.1- FPM docker pull mysql:5.7Copy the code

perform

  • Write docker-comemess. yml as a command script that creates a docker container with one click, sets up parameters, ports, address maps, and executes linxu commands. You can use this tutorial to learn about docker-compose in common use, just like markdown.
  • 1, project directory and nginx configuration mapping; Mysql > configure port and network configuration; mysql > configure port and network configuration; 2. Configure port and network configurations. Dockerfile is used to build an image and start a container. 2. Configure port and network configurations. 3, install the required PHP extension to the image
  • Docker – compose. Yml file
version: "3"
services:
  nginx:
    image: nginx:latest
    container_name: nginx
    ports:
      - "80:80"
    volumes:
      - ./code:/code  # Create a project root directory based on your situation
      - ./nginx/conf.d:/etc/nginx/conf.d  Ngixn configuration can be mapped for easy modification
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/logs:/var/log/nginx
    network_mode: "host"
  mysql:
    image: mysql:latest
    container_name: mysql
    command: --default-authentication-plugin=mysql_native_password
    volumes:
      - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime
      - ./mysql/data:/var/lib/mysql:rw Create /data/myql directory
      - ./mysql/logs:/var/lib/mysql-logs:rw  # / logs/mysql directory
    ports:
      - "3306:3306"
    environment:
      MYSQL_USER: root  
      MYSQL_PASSWORD: 123456 
      MYSQL_ROOT_PASSWORD: 123456
    network_mode: "host"PHP: build:./ container_name: fPM7.1 ports: -"9000:9000"
    working_dir: /code
    volumes:
      - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime
      - ./code:/code
      - ./php/php.ini:/usr/local/etc/php/php.ini
    network_mode: "host"
Copy the code
  • PHP image Dockerfile file
FROM PHP :7.1-fpm RUN apt-get update && apt-get install -y libpng-dev libjpeg-dev libpq-dev \ && rm -rf /var/lib/apt/lists/* \ && docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \ && docker-php-ext-install gd mbstring pdo pdo_mysql pdo_pgsql zip CMD ["php-fpm"]
Copy the code