Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Steps to deploy Apache+PHP+MariaDB+phpMyAdmin in a Docker container

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains the "steps to deploy Apache+PHP+MariaDB+phpMyAdmin in the Docker container". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the steps of deploying Apache+PHP+MariaDB+phpMyAdmin in the Docker container.

Create an Apache+PHP+phpMyAdmin image

First start the container of MariaDB

In the previous section, we know that the user name of the database is root and the password is 123456, but we still lack the ip address of the database. We use the following method to obtain the ip address of the docker instance, which is 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 hours 13306-> 3306/tcp dreamy_ Bell [roo t@test01] # docker inspect-- Format'{{.NetworkSettings.IPAddress}} '2e78c466919e172.17.0.3 [root@test01 ~] #

First create directories and files

[root@test01 ~] # mkdir phpMyAdmin_dockerfile & & cd phpMyAdmin_ dockerfile [root @ test01 phpMyAdmin_dockerfile] # lsconfig.inc.php Dockerfile httpd_init.sh phptest.php run.sh

Edit the Dockerfile file

The contents are as follows. The meaning of each line has been added to the comments.

[root@test01 phpMyAdmin_dockerfile] # cat Dockerfile # # basic image FROM centos:7.4.1708# used to add author information MAINTAINER liuxin 842887233@qq.com# working directory WORKDIR / root/# install httpd and php, and ignore errors RUN yum-y install httpdRUN yum-y install php# install mariadb client and php-mysqlndRUN yum-y install mariadbRUN yum-y install php-mysqlndRUN yum-y install php-mbstring# install phpmyadminRUN yum-y install epel-releaseRUN yum-y install phpmyadmin# set environment variables Easy to manage ENV MARIADB_ADDR 172.17.0.3ENV MARIADB_PORT 3306ENV MARIADB_USER rootENV MARIADB_PASS 12345 container to support Chinese ENV LC_ALL en_US.UTF-8# configuration 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# add php test interface ADD phptest.php / var/www/html/phptest.php# initializes httpd service ADD httpd_init.sh / root/httpd_init.shRUN chmod 775 / root/httpd_init.shRUN / root/httpd_init.sh# export port EXPOSE 8 add startup file ADD run.sh / root/run.shRUN chmod 775 / root/run.sh# setting default startup command CMD ["/ root/run.sh"]

Configure the profile for phpmyadmin

Here I upload the written configuration file directly, and then modify the file permissions. You can also configure it through a script, but it's troublesome and not as simple as this. The changed configuration is as follows

Set the login password for phpmyadmin

$cfg ['blowfish_secret'] =' 123456clients; / * YOU MUST FILL IN THIS FOR COOKIE AUTH! * / set the account, password, ip and port $cfg to connect to the database ['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'] [$] [' user'] = 'root'; / / MySQL user$cfg [' Servers'] [$I] ['password'] =' 123456]; / / MySQL password (only needed)

Use scripts to configure 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

Add a php test interface

[root@test01 phpMyAdmin_dockerfile] # cat phptest.php

< ?phpphpinfo();?>

Startup script

[root@test01 phpMyAdmin_dockerfile] # cat run.sh #! / bin/shhttpdwhile true;do sleep 1000 done

Create a mirror

[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.. Omit .Step 26: CMD / root/run.sh-> Using cache-> 19e52b9aceabSuccessfully built 19e52b9aceab [root@test01 phpMyAdmin_dockerfile] #

Create and start the container

Mapping, physical machine port 8080 to container port 80

[root@test01 phpMyAdmin_dockerfile] # docker run-d-p 8080 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 hours 8080-> 80/tcp sick_ride2e78c466919e liuxin/centos-mariadb:v1 "/ root/run.sh" 12 hours ago Up 4 hours 0.0.0.0 hours 13306-> 3306/tcp dreamy_ Bell [root @ test01 phpMyAdmin_dockerfile] #

Verification

Open a web browser and enter the web page for the test

Enter the address of phpmyadmin, and enter the account password to see if you can log in.

Login is successful, and you are done.

Thank you for reading, the above is the content of "steps for deploying Apache+PHP+MariaDB+phpMyAdmin in Docker container". After the study of this article, I believe you have a deeper understanding of the steps of deploying Apache+PHP+MariaDB+phpMyAdmin in Docker container, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report