docker 搭建 lnmp 环境

henryspace 记录精彩的程序人生 本文由博客端 https://henryspace.cn 主动推送

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

  • PHP

    PHP(Hypertext Preprocessor)是一种开源脚本语言。语法吸收了 C 语言、 Java 和 Perl 的特点,主要适用于 Web 开发领域,据说是世界上最好的编程语言。

    156 引用 • 399 回帖 • 596 关注
  • Docker

    Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的操作系统上。容器完全使用沙箱机制,几乎没有性能开销,可以很容易地在机器和数据中心中运行。

    397 引用 • 851 回帖 • 343 关注

广告 我要投放

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...