文章目录
- 文件目录
- docker-compose.yml
- 执行 docker-compose.yml
文件目录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | /home/project/ ├── docker-compose.yml ├── mysql │ ├── conf │ │ └── my.cnf │ ├── data │ ├── init.sql │ ├── logs │ │ ├── error.log │ │ └── general.log │ └── privileges.sql ├── nginx │ ├── conf.d │ │ └── web.conf │ ├── log │ │ ├── access.log │ │ └── error.log │ ├── mime.types │ ├── nginx.conf │ ├── nginx.dockerfile │ ├── ssl │ └── users ├── php │ ├── local.ini │ └── www.log.slow └── www │ ├── php.dockerfile │ └── 项目的web |
docker-compose.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | version: "3.7" services: php: build: context: $PWD dockerfile: ./www/php.dockerfile image: php7.3.3-fpm container_name: web_php restart: unless-stopped tty: true environment: SREVICE_TAG: prod SERVICE_NAME: php volumes: - /etc/localtime:/etc/localtime - $PWD/www:/var/www/html/web - $PWD/php/local.ini:/usr/local/etc/php/cond.d/local.ini working_dir: /var/www/html/web networks: - web_net nginx: build: context: $PWD dockerfile: ./nginx/nginx.dockerfile image: nginx:1.15.8 container_name: web_nginx restart: unless-stopped tty: true ports: - 80:80 working_dir: /var/www/html/web volumes: - /etc/localtime:/etc/localtime - $PWD/nginx/users:/etc/nginx/users - $PWD/nginx/nginx.conf:/etc/nginx/nginx.conf - $PWD/nginx/conf.d/web.conf:/etc/nginx/conf.d/web.conf - $PWD/nginx/log:/var/log/nginx - $PWD/www:/var/www/html/web networks: - web_net depends_on: - php mysql: image: mysql:5.7.25 container_name: web_mysql restart: unless-stopped volumes: - /etc/localtime:/etc/localtime - $PWD/mysql/data:/var/lib/mysql - $PWD/mysql/conf/my.cnf:/etc/mysql/my.cnf - $PWD/mysql/init.sql:/docker-entrypoint-initdb.d/init.sql:ro - $PWD/mysql/privileges.sql:/docker-entrypoint-initdb.d/privileges.sql:ro networks: - web_net environment: MYSQL_ROOT_PASSWORD: <root 用户密码> MYSQL_USER: <userA> MYSQL_PASSWORD: <userA 的密码> MYSQL_DATABASE: <新增数据库> networks: web_net: driver: bridge external: name: web_net # 需要先用docker network create web_net 命令创建好 |
执行 docker-compose.yml
1 | docker-compose up -d |