henryspace

记录精彩的程序人生 开始使用

docker 搭建 lnmp 环境

docker-composer 的安装

sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

构建脚本:

php5.6 lnmp环境 搭建yml

# docker version:  18.06.0+
# docker-compose version: 1.23.2+
# OpenSSL version: OpenSSL 1.1.0h
version: "3.7"
services:
  web:
    image: nginx
    container_name: nginx
    hostname: nginx-web
    ports:
      # 如果宿主机80端口被占用,可自行修改为其他port(>=1024)
      # 0.0.0.0:要绑定的宿主机端口:docker容器内端口80
      - "8081:80"
    volumes:
      - "/home/lory/env/nginx/www:/usr/share/nginx/html:ro"
      - "/home/lory/env/nginx/conf/conf.d:/etc/nginx/conf.d:ro"
    depends_on:
      - php
    restart: always

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: phpmyadmin
    environment:
      - PMA_ARBITRARY=1
    env_file:
      - ./walle.env
    ports:
      - "8285:80"
    depends_on:
      - db
    restart: always

  db:
    image: "mysql:5.7"
    container_name: "mysql"
    env_file:
      - ./walle.env
    ports:
      - "3307:3306"
    volumes:
      - "./db:/var/lib/mysql"
      - "./conf/my.cnf:/etc/my.cnf"
      - "./init:/docker-entrypoint-initdb.d/"
    restart: always

  redis:
    image: "redis"
    container_name: "redis"
    env_file:
      - ./walle.env
    ports:
      - "6379:6379"
    restart: always


  php:
    image: "php:5.6-fpm"
    container_name: "myphp"
    env_file:
      - ./walle.env
    ports:
      - "9000:9000"
    volumes:
      - "/home/lory/env/nginx/www:/www"
    restart: always

php 7.2 lnmp 环境搭建

# docker version:  18.06.0+
# docker-compose version: 1.23.2+
# OpenSSL version: OpenSSL 1.1.0h
version: "3.7"
services:
  web:
    image: nginx
    container_name: nginx
    hostname: nginx-web
    ports:
      # 如果宿主机80端口被占用,可自行修改为其他port(>=1024)
      # 0.0.0.0:要绑定的宿主机端口:docker容器内端口80
      - "8081:80"
    volumes:
      - "/home/lory/env/nginx/www:/usr/share/nginx/html:ro"
      - "/home/lory/env/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro"
      - "/home/lory/env/nginx/conf/conf.d:/etc/nginx/conf.d:ro"
    depends_on:
      - php
    restart: always

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: phpmyadmin
    environment:
      - PMA_ARBITRARY=1
    env_file:
      - ./walle.env
    ports:
      - "8285:80"
    depends_on:
      - db
    restart: always

  db:
    image: "mysql:5.7"
    container_name: "mysql"
    env_file:
      - ./walle.env
    ports:
      - "3307:3306"
    volumes:
      - "./db:/var/lib/mysql"
      - "./conf/my.cnf:/etc/my.cnf"
      - "./init:/docker-entrypoint-initdb.d/"
    restart: always

  redis:
    image: "redis"
    container_name: "redis"
    env_file:
      - ./walle.env
    ports:
      - "6379:6379"
    restart: always


  php:
    image: "php:7.2-fpm"
    container_name: "myphp"
    env_file:
      - ./walle.env
    ports:
      - "9000:9000"
    volumes:
      - "/home/lory/env/nginx/www:/www"
    restart: always

帮助文档: https://www.jianshu.com/p/43037ce40b00

docker文档: https://www.runoob.com/docker/docker-compose.html

请成为永远疯狂永远浪漫永远清澈的存在。

评论
留下你的脚步
推荐阅读