docker-compose部署lnmp、redis

2022-09-25  本文已影响0人  耍帅oldboy

1、docker-compose.yml

version: "3"
services:
  nginx:
    build: .
    container_name: nginx
    ports:
      - "80:80"
    volumes:
      - "/home/docker/lnmp/nginx/html:/usr/share/nginx/html"
      - "/etc/localtime:/etc/localtime:ro"
      - "/home/docker/lnmp/nginx/conf:/etc/nginx"
      - "/home/docker/lnmp/nginx/log:/var/log/nginx"
    image: nginx:latest
    restart: always
  mysql:
    build: .
    container_name: mysql
    ports:
      - "3306:3306"
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "/home/docker/lnmp/mysql/data:/var/lib/mysql"
      - "/home/docker/lnmp/mysql/etc/my.cnf:/etc/my.cnf"
    image: mysql:5.7.39
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 123456abc
  php-fpm7.4:
    build: ./php7.4
    container_name: php-fpm7.4
    ports:
      - "9001:9000"
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "/home/docker/lnmp/php-fpm7.4/conf:/usr/local/etc"
      - "/home/docker/lnmp/nginx/html:/var/www/html"
    restart: always
  redis:
    container_name: redis
    privileged: true
    ports:
      - "6379:6379"
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "/home/docker/lnmp/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf"
      - "/home/docker/lnmp/redis/data:/data"
      - "/home/docker/lnmp/redis/logs:/logs"
    image: redis:latest
    restart: always
    environment:
      - TZ="Asia/Shanghai"
    command: ["redis-server","/usr/local/etc/redis/redis.conf","--appendonly yes"]

2、default.conf

    location ~ \.php$ {
        root           /usr/share/nginx/html/default;
        fastcgi_pass   php-fpm7.4:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/html/default/$fastcgi_script_name; #注意这里填写的是php-fpm7.4容器的地址
        include        fastcgi_params;
    }

3、redis扩展安装,php7.4/Dockerfile配置

FROM php:7.4-fpm
RUN pecl install redis-5.1.1

4、安装redis,redis.conf配置

#开启保护,必须配置密码,否则其他都无法链接
protected-mode yes
#开启远程连接 
#bind 127.0.0.1 
#自定义密码
#requirepass 12345678 
port 6379
timeout 0
# 900s内至少一次写操作则执行bgsave进行RDB持久化
save 900 1 
save 300 10
save 60 10000
rdbcompression yes
dbfilename dump.rdb
dir /data
#logfile "/logs/log"
appendonly yes
appendfsync everysec

5、运行结果

[root@VM-16-3-centos lnmp]# docker-compose ps
   Name                 Command               State                          Ports                       
---------------------------------------------------------------------------------------------------------
mysql        docker-entrypoint.sh mysqld      Up      0.0.0.0:3306->3306/tcp,:::3306->3306/tcp, 33060/tcp
nginx        /docker-entrypoint.sh ngin ...   Up      0.0.0.0:80->80/tcp,:::80->80/tcp                   
php-fpm7.4   docker-php-entrypoint php-fpm    Up      0.0.0.0:9001->9000/tcp,:::9001->9000/tcp           
redis        docker-entrypoint.sh redis ...   Up      0.0.0.0:6379->6379/tcp,:::6379->6379/tcp    
上一篇下一篇

猜你喜欢

热点阅读