Docker容器里部署Apache+PHP+MariaDB+phpMyAdmin的步骤
这篇文章主要讲解了"Docker容器里部署Apache+PHP+MariaDB+phpMyAdmin的步骤",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"Docker容器里部署Apache+PHP+MariaDB+phpMyAdmin的步骤"吧!
创建Apache+PHP+phpMyAdmin镜像
首先启动MariaDB的容器
在上一节中我们知道数据库的用户名是root,密码是123456,但是我们还缺少数据库的ip地址,我们使用如下方法获取docker实例的ip地址,是172.17.0.3
[root@test01 ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES2e78c466919e liuxin/centos-mariadb:v1 "/root/run.sh" 11 hours ago Up 3 hours 0.0.0.0:13306->3306/tcp dreamy_bell[root@test01 ~]# docker inspect --format '{{ .NetworkSettings.IPAddress }}' 2e78c466919e172.17.0.3[root@test01 ~]#
首先创建目录和文件
[root@test01 ~]# mkdir phpMyAdmin_dockerfile && cd phpMyAdmin_dockerfile[root@test01 phpMyAdmin_dockerfile]# lsconfig.inc.php Dockerfile httpd_init.sh phptest.php run.sh
编辑Dockerfile文件
内容如下。具体每行的意思已经添加到注释中了
[root@test01 phpMyAdmin_dockerfile]# cat Dockerfile ##使用的基础镜像FROM centos:7.4.1708#添加作者信息MAINTAINER liuxin 842887233@qq.com#工作目录WORKDIR /root/#安装httpd和php,并忽略错误RUN yum -y install httpdRUN yum -y install php#安装mariadb客户端和php-mysqlndRUN yum -y install mariadbRUN yum -y install php-mysqlndRUN yum -y install php-mbstring#安装phpmyadminRUN yum -y install epel-releaseRUN yum -y install phpmyadmin#设置环境变量,便于管理ENV MARIADB_ADDR 172.17.0.3ENV MARIADB_PORT 3306ENV MARIADB_USER rootENV MARIADB_PASS 123456#让容器支持中文ENV LC_ALL en_US.UTF-8#配置phpmyadmin#ADD phpMyAdmin.conf /etc/httpd/conf.d/phpMyAdmin.confADD config.inc.php /etc/phpMyAdmin/config.inc.phpRUN chown root:apache /etc/phpMyAdmin/config.inc.phpRUN chmod 640 /etc/phpMyAdmin/config.inc.php#添加php测试界面ADD phptest.php /var/www/html/phptest.php#初始化httpd服务ADD httpd_init.sh /root/httpd_init.shRUN chmod 775 /root/httpd_init.shRUN /root/httpd_init.sh#导出端口EXPOSE 80#添加启动文件ADD run.sh /root/run.shRUN chmod 775 /root/run.sh#设置默认启动命令CMD ["/root/run.sh"]
配置phpmyadmin的配置文件
这里我直接将写好的配置文件上传,然后修改文件权限。也可以通过 脚本 来配置,不过比较麻烦,不如这个简单。改动的配置如下
设置phpmyadmin的登录密码
$cfg['blowfish_secret'] = '123456'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */设置连接数据库的账号、密码、ip和端口$cfg['Servers'][$i]['host'] = '172.17.0.3'; // MySQL hostname or IP address$cfg['Servers'][$i]['port'] = ''; // MySQL port - leave blank for default port$cfg['Servers'][$i]['user'] = 'root'; // MySQL user$cfg['Servers'][$i]['password'] = '123456'; // MySQL password (only needed
使用 脚本 配置httpd
[root@test01 phpMyAdmin_dockerfile]# cat httpd_init.sh #!/bin/shsed -i 's/#ServerName www.example.com:80/ServerName localhost:80/g' /etc/httpd/conf/httpd.confsed -i '/Require ip/d' /etc/httpd/conf.d/phpMyAdmin.confsed -i '//a Require all granted' /etc/httpd/conf.d/phpMyAdmin.conf
添加一个php测试界面
[root@test01 phpMyAdmin_dockerfile]# cat phptest.php < ?phpphpinfo();?>
启动脚本
[root@test01 phpMyAdmin_dockerfile]# cat run.sh #!/bin/shhttpdwhile true;do sleep 1000;done
创建镜像
[root@test01 phpMyAdmin_dockerfile]# docker build -t liuxin/centos-phpmyadmin:v1 ./Sending build context to Docker daemon 14.34 kBStep 1 : FROM centos:7.4.1708 ---> 3afd47092a0e..省略.....Step 26 : CMD /root/run.sh ---> Using cache ---> 19e52b9aceabSuccessfully built 19e52b9aceab[root@test01 phpMyAdmin_dockerfile]#
创建并启动容器
映射,物理机端口8080到容器的80端口
[root@test01 phpMyAdmin_dockerfile]# docker run -d -p 8080:80 liuxin/centos-phpmyadmin:v1 /root/run.sha5a54528879ea95e9bf98a7ba3fbf6236b26f3a54a5305738a4ee770164f105b[root@test01 phpMyAdmin_dockerfile]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESa5a54528879e liuxin/centos-phpmyadmin:v1 "/root/run.sh" 56 seconds ago Up 54 seconds 0.0.0.0:8080->80/tcp sick_ride2e78c466919e liuxin/centos-mariadb:v1 "/root/run.sh" 12 hours ago Up 4 hours 0.0.0.0:13306->3306/tcp dreamy_bell[root@test01 phpMyAdmin_dockerfile]#
验证
打开web浏览器,输入测试的网页
输入phpmyadmin的地址,并输入账号密码,看能否登录
登录成功,大功告成
感谢各位的阅读,以上就是"Docker容器里部署Apache+PHP+MariaDB+phpMyAdmin的步骤"的内容了,经过本文的学习后,相信大家对Docker容器里部署Apache+PHP+MariaDB+phpMyAdmin的步骤这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!
- 上一篇
MySQL的server_uuid获取之uuid()函数和uuid_short()函数
1、uuid()函数mysql> select uuid(),uuid();+--------------------------------------+----------------------
- 下一篇
[AlwaysOn2017] AlwaysOn的DMV和DMF - Sys.dm_hadr_database_replica_cluster_states
17、 Sys. dm_hadr_database_replica_cluster_states返回一行信息,这些信息可便于洞察Windows Server故障转移群集(WSFC)上每个AlwaysO