您现在的位置是:首页 > Linux OSLinux OS

nginx+php+mysql+redis docker安装

比目鱼2022-08-28【Linux OS】人已围观

简介# 搜索nginx镜像https://hub.docker.com/ 在hub.docker上找到对应的镜像# 拉取nginx镜像docker pull nginx:latest# 检查镜像是否拉取成功docker images# 运行一个测试的ng

# 搜索nginx镜像

https://hub.docker.com/  在hub.docker上找到对应的镜像

# 拉取nginx镜像

docker pull nginx:latest

# 检查镜像是否拉取成功

docker images

# 运行一个测试的nginx

docker run -d --name nginxtest nginx

# 把容器里的nginx目录复制出来,配置是放在/etc/nginx

docker cp nginxtest:/etc/nginx ./

# 把容器里的log目录复制出来,日志是放在/var/log

docker cp nginxtest:/var/log ./

# 删除测试的nginx-test

docker rm -f nginxtest

# 查看nginx配置结构

[root@localhost ~]# tree nginx

nginx

├── conf.d

│   └── default.conf

├── fastcgi_params

├── mime.types

├── modules -> /usr/lib/nginx/modules

├── nginx.conf

├── scgi_params

└── uwsgi_params

# 查看log日志结构

[root@localhost ~]# tree log

log

├── apt

│   ├── eipp.log.xz

│   ├── history.log

│   └── term.log

├── btmp

├── dpkg.log

├── faillog

├── lastlog

├── nginx

│   ├── access.log -> /dev/stdout

│   └── error.log -> /dev/stderr

└── wtmp




# 拉取php镜像

docker pull php:7.4.28-fpm

# 检查镜像是否拉取成功

docker images

# 运行一个测试的php

docker run -d --name phptest php:7.4.28-fpm

# 把容器里的php目录复制出来,进容器php -i | grep php.ini可查看配置文件目录

docker cp phptest:/usr/local/etc/php ./

# 删除测试的php-test

docker rm -f phptest

# 查看php目录

[root@localhost ~]# tree php

php

├── conf.d

│   └── docker-php-ext-sodium.ini

├── php.ini-development

└── php.ini-production



# 拉取mysql镜像

docker pull mysql:5.7.38

# 检查镜像是否拉取成功

docker images

# 运行一个测试的mysql

docker run -d --name mysqltest mysql:5.7.38

# 把容器里的my.cnf复制出来

docker cp mysqltest:/etc/my.cnf ./

# 删除测试的mysqltest

docker rm -f mysqltest

# 查看php目录

[root@localhost ~]# tree mysql

mysql

├── etc

│   └── my.cnf


[root@VM-16-14-centos web]# cat docker-compose.yml
version: "3"
services:
    nginx:
        image: nginx:latest
        container_name: "compose-nginx"
        restart: always
        ports:
            - "80:80"
            - "443:443"
        environment:
           - TZ=Asia/Shanghai
        depends_on:
           - "php"
        volumes:
           - "/web/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf"
           - "/web/nginx/log:/var/log/nginx"
           - "/web/www:/usr/share/nginx/www"
        networks:
           - net-app
    php:
        image: php:7.2.0-fpm
        container_name: "compose-php"
        restart: always
        ports:
            - "9000:9000"
        environment:
            - TZ=Asia/Shanghai
        volumes:
            - "/web/www:/usr/share/nginx/www"
            - "/web/php/conf.d/php.ini:/usr/local/etc/php/php.ini"
        networks:
           - net-app
    mysql:
        image: "mysql:5.7.38"
        container_name: "compose-mysql"
        environment:
            MYSQL_ROOT_PASSWORD: "123456"
        command: --default-authentication-plugin=mysql_native_password
        # restart: always
        volumes:
            - "/web/mysql/data:/var/lib/mysql"
            - "/web/mysql/etc/my.cnf:/etc/my.cnf"
        ports:
            - "3306:3306"
            - "33060:33060"
        networks:
           - net-app
    redis:
        image: redis:5.0.14
        container_name: "compose-redis"
        ports:
            - "6379:6379"
        networks:
           - net-app
networks:
    net-app:
docker rm -f compose-nginx
docker rm -f compose-php
docker rm -f compose-mysql
docker rm -f compose-redis

docker-compose up -d



php安装mysql组件pdo(貌似hub上的的5.6x版本安装pdo会有问题没弄通,7.x的执行下面两条命令就会通)

进入php容器
docker exec -it compose-php /bin/bash
执行安装
$ docker-php-ext-install pdo

$ docker-php-ext-install pdo_mysql


phpinfo()执行后有下面信息,表示pdo_mysql安装成功


PDO

PDO supportenabled
PDO driverssqlite, mysql

pdo_mysql

PDO Driver for MySQLenabled
Client API versionmysqlnd 5.0.12-dev - 20150407 - $Id: b396954eeb2d1d9ed7902b8bae237b287f21ad9e $
DirectiveLocal ValueMaster Value
pdo_mysql.default_socketno valueno value


Tags:

很赞哦! ()

随机图文

文章评论

    共有条评论来说两句吧...

    用户名:

    验证码:

本站推荐

站点信息

  • 建站时间:2021-06-18
  • 网站主题:编程技术博客
  • 文章统计50篇文章
  • 标签管理标签云
  • 博主微信号:比目鱼