mysql打包成docker_web应用如何打包成docker镜像?

该博客介绍了如何利用Docker Compose来部署一个包含Nginx web服务器、PHP-FPM处理器、MySQL数据库和Redis缓存服务的完整应用堆栈。配置文件详细定义了各服务的映射端口、数据卷、环境变量以及日志设置,确保了服务间的依赖和通信。
摘要由CSDN通过智能技术生成

用docker-compose组织吧,类似这种

version: '3.7'

x-logging: &default-logging

driver: "json-file"

options:

max-size: "20m"

max-file: "10"

services:

### Nginx container ##########################################################

nginx:

image: nginx

ports:

- "80:80"

- "443:443"

volumes:

- wwwroot:/var/www/html:ro

- ./work/nginx/entrypoint.conf:/etc/nginx/nginx.conf:ro

- ./work/nginx:/etc/nginx/conf.d:ro

- ./work/logs:/var/log/nginx:rw

- /etc/localtime:/etc/localtime:ro

restart: always

container_name: nginx

depends_on:

- mysql

- redis

logging: *default-logging

### PHP-FPM container ########################################################

php-fpm:

image: php7.3-fpm

volumes:

- wwwroot:/var/www/html:rw

- ./work/php/php.ini:/usr/local/etc/php/php.ini:ro

- ./work/php/php-fpm.conf:/usr/local/etc/php-fpm.d/www.conf:ro

- ./work/logs:/var/log:rw

- /etc/localtime:/etc/localtime:ro

privileged: false

container_name: php-fpm

logging: *default-logging

### Mysql container ##########################################################

mysql:

image: mysql:5.7

ports:

- "127.0.0.1:3306:3306/tcp"

secrets:

- db_root_password

- db_password

volumes:

- mysqldata:/var/lib/mysql:rw

- ./work/mysql/mysql.cnf:/etc/mysql/my.cnf:ro

- ./work/logs:/var/log/mysql:rw

- /etc/localtime:/etc/localtime:ro

restart: always

container_name: mysql

environment:

MYSQL_USER: ${MYSQL_USER}

MYSQL_DATABASE: ${MYSQL_DATABASE}

MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_root_password

MYSQL_PASSWORD_FILE: /run/secrets/db_password

logging: *default-logging

### Redis container ##########################################################

redis:

image: redis:5.0

entrypoint:

- redis-server

- /usr/local/etc/redis/redis.conf

volumes:

- ./work/redis/redis.conf:/usr/local/etc/redis/redis.conf:ro

- ./work/logs:/var/log/redis:rw

- /etc/localtime:/etc/localtime:ro

restart: always

container_name: redis

logging: *default-logging

volumes:

wwwroot:

mysqldata:

secrets:

db_root_password:

file: ./db_root_password.txt

db_password:

file: ./db_${MYSQL_USER}_password.txt

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值