假设我们已经使用dockefile构建好我们需要的PHP镜像,并且创建好所需的目录,配置好了nginx配置文件,那么,我们可以使用docke-compose来管理我们的三个容器,我们编写docker-compose.yml文件,内容如下:

version: "3"
services:
  mysql:
    image: mysql:5.7
    container_name: mysql_compose
    environment:
      MYSQL_ROOT_PASSWORD: root
    ports:
      - "13306:3306"
    volumes:
      - /var/mysql:/var/lib/mysql
    networks:
      - lnmp
      
  php:
    image: php72:ext
    container_name: php_compose
    volumes:
      - /www:/usr/share/nginx/html
    networks:
      - lnmp

  nginx:
    image: nginx:latest
    container_name: nginx_compose
    ports:
      - "80:80"
    volumes:
      - /var/nginx:/etc/nginx:ro
      - /www:/usr/share/nginx/html
    # links:
    #   - php:php
    depends_on:
      - php
    networks:
      - lnmp

networks:
   lnmp:
     driver: bridge

然后在该文件目录下执行:

docker-compose up -d

输出如下:

Starting mysql_compose ... done
Starting php_compose   ... done
Starting nginx_compose ... done

此时,运行PHP的服务已经运行在后台啦~

点赞(6) 联系站长
返回
顶部