Docker lnmp Docker-compose搭建nginx+php+mysql
目录
Docker-Compose install
How to Create a MySql Instance with Docker Compose
php
mkdir docker4php && cd docker4php vi Dockerfile FROM php:7.1-fpm-stretch #原来是这个 但是这个就不能apt 如果要和下面对应 要改一下 #FROM php:7.1-fpm-alpine Run apt-get update \ && apt install iputils-ping \ && docker-php-ext-install mysqli && docker-php-ext-enable mysqli
compose
mkdir npm4compose cd npm4compose mkdir conf.d php html cd conf.d && touch nginx.conf cd - cd html && touch index.php && echo "<?php phpinfo(); ?>" >index.php cd .. mv ~/docker4php/Dockerfile ./php/ [root@localhost npm4compose]# tree . |-- conf.d | `-- nginx.conf |-- docker-compose.yml |-- html | `-- index.php `-- php `-- Dockerfile vi docker-compose.yml version: '3' services: nginx: image: nginx:latest ports: - "80:80" depends_on: - "php" volumes: - "${PWD}/conf.d:/etc/nginx/conf.d" - "${PWD}/html:/usr/share/nginx/html" networks: - d_net container_name: "compose-nginx" php: build: ./php #指定build Dockerfile生成镜像 image: php:7.1-fpm-alpine ports: - "9000:9000" volumes: - "$PWD/html:/var/www/html" networks: - d_net container_name: "compose-php" mysql: image: mysql:5.7 ports: - "3306:3306" environment: MYSQL_DATABASE: 'db' # So you don't have to use root, but you can if you like MYSQL_USER: 'evan' # You can use whatever password you like MYSQL_PASSWORD: '123456' # Password for root access MYSQL_ROOT_PASSWORD: '123456' expose: # Opens port 3306 on the container - '3306' networks: - d_net container_name: "compose-mysql" networks: d_net: driver: bridge vi conf.d/nginx.conf server{ listen 80; server_name a.com; #server_name localhost; location /{ root /var/www/html; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/html; } location ~ \.php$ { include fastcgi_params; fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name; } } docker-compose up -d
php连接mysql
测试检查
[root@work2 npm4compose]# docker-compose ps Name Command State Ports ----------------------------------------------------------------------------------------- compose-mysql docker-entrypoint.sh mysqld Up 0.0.0.0:3306->3306/tcp, 33060/tcp compose-nginx nginx -g daemon off; Up 0.0.0.0:80->80/tcp compose-php docker-php-entrypoint php-fpm Up 0.0.0.0:9000->9000/tcp docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0e2e7b200b47 nginx:latest "nginx -g 'daemon of…" 5 minutes ago Up 5 minutes 0.0.0.0:80->80/tcp compose-nginx b0990f13ddd2 mysql:5.7 "docker-entrypoint.s…" 5 minutes ago Up 5 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp compose-mysql e0ff739663a9 php:7.1-fpm-alpine "docker-php-entrypoi…" 5 minutes ago Up 5 minutes 0.0.0.0:9000->9000/tcp compose-php http://192.168.88.22/index.php dns cat /etc/hosts 192.168.88.22 a.com
mysql暂时不用这个
docker pull mysql:8.0
How to Create a MySql Instance with Docker Compose
trouble
docker-compose up -d ERROR: The Compose file './docker-compose.yml' is invalid because: services.php.networks contains {"d_net": null}, which is an invalid type, it should be a string networks: - d_net : :不能要 [root@localhost npm4compose]# cat php/Dockerfile FROM php:7.1-fpm-alpine Run apt-get update \ && apt install iputils-ping \ && docker-php-ext-install mysqli && docker-php-ext-enable mysqli 这个alpine 他居然安装软件是apt 我去 这么搞笑 nginx: image: nginx:lastest ports: 这些单词 拼写 我去 , 定义网络叫app_net 写在应用又写了d_net container_name: "compose-php" mysql: image: mysql:8.0 ports: - "3306:3306" environment: - MYSQL_ROOT_PASSWORD={your_passwd} networks: - d_net container_name: "compose-mysql" networks: #配置docker 网络 app_net: driver: bridge
see also
基于Dockerfile构建LNMP(good-php扩展php7+mysql+nginx
docker-compose部署LNMP环境 Nginx(Openresty)、MySQL5.7、PHP7.2(5.6)、Redis5.0、PHPMyAdmin、Xdebug
Nginx 1.15.X Linux Debian/Ubuntu 源码编译安装 LNMP之Nginx
MySQL 5.6 Linux Debian/Ubuntu源码编译安装 LNMP之MySQL
在 Debian 上源码编译和安装 Nginx+PHP+FastCGI+MySQL
good_testmysql-docker-compose搭建nginx+php+mysql
从零开始学习Docker - 搭建 nginx+mysql+php 环境
使用Docker-Compose搭建nginx+php+mysql基础应用
https://github.com/kkmike999/docker-compose-php-nginx-mysql/blob/master/docker-compose.yml
compose install more PHP extensions
使用docker-composer创建一个mysql容器,并创建一个database且指定其编码集为中文utf8
Docker docker-compose 配置Nginx+Php+Mysql开发环境
docker-compose搭建 Nginx+PHP+MySQL 环境
从零开始学习Docker - 搭建 nginx+mysql+php 环境
docker-compose 部署 nginx + php-fpm + mysql + phpmyadmin