【docker】Apache+mysql+phpmyadmin网站系统

01.下载lamp

[root@es1 nginx]# docker search lamp
NAME                                      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mattrayner/lamp                           A simple LAMP docker image running the prere…   351                  [OK]
linode/lamp                               LAMP on Ubuntu 14.04.1 LTS Container            180                  
tutum/lamp                                Out-of-the-box LAMP image (PHP+MySQL)           155                  
fauria/lamp                               Modern, developer friendly LAMP stack. Inclu…   121                  [OK]
greyltc/lamp                              a super secure, up-to-date and lightweight L…   103                  [OK]
janes/alpine-lamp                         lamp base on alpine linux                       41                   [OK]
dgraziotin/lamp                                                                           11                   [OK]
theodotos/ubuntu-lamp                     A LAMP (Linux/Apache/MariaDB/PHP) image base…   7                    
machines/la_p7                            Just a ubuntu based lamp server                 5                    
lampson0505/ubuntu-phy                    An Ubuntu image with teamd for network inter…   4                    
dockette/devstack                         My LAMP/Devstack Dockerfile                     4                    [OK]
lampnick/doctron                          Doctron supply html convert to pdf, html con…   3                    
lampe/minimal-nginx                       A minimal image for nginx - created with mak…   3                    
javanile/lamp                             Ready to use LAMP stack                         2                    [OK]
davidsal/lamp-armv7                       LAMP image for ARM32v7 (like Raspberry Pi) b…   1                    
lampepfl/dotty                            Dotty testing image                             0                    
lampochka/subsonic                                                                        0                    
lampepfl2022/cs206                                                                        0                    
canersimsek/lampbox                       LAMP Box                                        0                    
lampofgod/docker-php7.0-nodejs-composer                                                   0                    
lampdatabase/safa                                                                         0                    
lampepfl/moocs-dotty                                                                      0                    
lampepfl/moocs                                                                            0                    
lampepfl/dockerclient                                                                     0                    
lampholder/controlroom-bot
--下载lamp 
docker pull mattrayner/lamp 
[root@es1 nginx]# docker pull mattrayner/lamp 
Using default tag: latest
latest: Pulling from mattrayner/lamp
35807b77a593: Pull complete 
ccfecfa17ed6: Pull complete 
499764c8dc6b: Pull complete 
c6b0ddc4cdc0: Pull complete 
8ae8ee891eaf: Pull complete 
510e2baf4b24: Pull complete 
4103a3ecbaab: Pull complete 
3066e34dc7b7: Pull complete 
b626f562f102: Pull complete 
fad4a5a21cfc: Pull complete 
9c2a40162cc1: Pull complete 
a8b002eab6c2: Pull complete 
cda2d831f3ac: Pull complete 
36cd807eb11e: Pull complete 
7418cc89daa3: Pull complete 
c5690feb59a2: Pull complete 
b836b3984976: Pull complete 
078cd7ee493e: Pull complete 
1c368befafd5: Pull complete 
7ed553304ebc: Pull complete 
eca287b55180: Pull complete 
cd928c8d6aad: Pull complete 
e199caef4ca7: Pull complete 
aca8e22d2fca: Pull complete 
Digest: sha256:f7caeba589eaea7e3d20f4ae3e3bf88233e66e7df59eb5adb49161a5365f9f90
Status: Downloaded newer image for mattrayner/lamp:latest
docker.io/mattrayner/lamp:latest



[root@es1 nginx]# docker images |grep lamp
mattrayner/lamp                           latest        c15726116aef   2 years ago      1.06GB
192.168.1.11:443/myharbor/lamp            latest-1804   2d9935d1db98   2 years ago      931MB
mattrayner/lamp                           latest-1804   2d9935d1db98   2 years ago      931MB

2.使用lamp docker images

--将下载的镜像 lamp 推送的我们的 harbor仓库中。
docker tag mattraynerlatest-1804 192.168.1.11:443/myharbor/lamp:latest-1804
docker push 192.168.1.11:443/myharbor/lamp:latest-1804

3.使用MySQL;



--后面的路径指的是docker里面的路径,前面的路劲是操作系统的路径。

--创建mysql容器 
docker run -it -d -p 80:80 -p 3306:3306 --name mylamp_mysql -h mylamp_mysql -v /data/lamp/app:/app \
 mattrayner/lamp:latest-1804
--检查容器 
[root@es1 nginx]# docker ps
CONTAINER ID   IMAGE                         COMMAND                  CREATED          STATUS          PORTS                                                                          NAMES
ee06900d895e   mattrayner/lamp:latest-1804   "/run.sh"                7 seconds ago    Up 6 seconds    0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp   mylamp_mysql
f37702dd598c   nginx:1.20.2.base             "nginx -g 'daemon of…"   57 minutes ago   Up 57 minutes   0.0.0.0:8081->80/tcp, :::8081->80/tcp                                          mynginxweb



--输出的过程有信息如下:
docker logs mylamp_mysql
[root@es1 nginx]# docker logs mylamp_mysql
Updating for PHP 8.0
Replacing CLI php.ini values
Editing APACHE_RUN_GROUP environment variable
Editing phpmyadmin config
Setting up MySQL directories
Allowing Apache/PHP to write to the app
Allowing Apache/PHP to write to MySQL
Editing MySQL config
=> An empty or uninitialized MySQL volume is detected in /var/lib/mysql
=> Installing MySQL ...
=> Done!
=> Waiting for confirmation of MySQL service startup
=> Creating MySQL admin user with random password
ERROR 1133 (42000) at line 1: Can't find any matching row in the user table
=> Done!
========================================================================
You can now connect to this MySQL Server with jILUaq7IeTYn

    mysql -uadmin -pjILUaq7IeTYn -h<host> -P<port>

Please remember to change the above password as soon as possible!
MySQL user 'root' has no password but only allows local connections

enjoy!
========================================================================
Starting supervisord
/usr/local/lib/python3.6/dist-packages/supervisor-4.2.2-py3.6.egg/supervisor/options.py:475: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
  'Supervisord is running as root and it is searching '
2024-07-05 08:42:53,014 CRIT Supervisor is running as root.  Privileges were not dropped because no user is specified in the config file.  If you intend to run as root, you can set user=root in the config file to avoid this message.
2024-07-05 08:42:53,015 INFO Included extra file "/etc/supervisor/conf.d/supervisord-apache2.conf" during parsing
2024-07-05 08:42:53,015 INFO Included extra file "/etc/supervisor/conf.d/supervisord-mysqld.conf" during parsing
2024-07-05 08:42:53,025 INFO RPC interface 'supervisor' initialized
2024-07-05 08:42:53,025 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2024-07-05 08:42:53,025 INFO supervisord started with pid 1
2024-07-05 08:42:54,029 INFO spawned: 'apache2' with pid 445
2024-07-05 08:42:54,032 INFO spawned: 'mysqld' with pid 446
2024-07-05 08:42:55,512 INFO success: apache2 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2024-07-05 08:42:55,512 INFO success: mysqld entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
'


容器数据库的目录必须挂载到外面,负责容易丢失数据/

--进入容器后可以免密登陆。然后修改admin用户的密码:admin123;

root@mylamp_mysql:/# mysql -uroot 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.35-0ubuntu0.18.04.2 (Ubuntu)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases; 
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
select version();
mysql> select version();
+-------------------------+
| version()               |
+-------------------------+
| 5.7.35-0ubuntu0.18.04.2 |
+-------------------------+
1 row in set (0.00 sec)
drop user 'sspu'@'%';
create user 'sspu'@'%' identified by 'sspu';
alter user 'admin'@'%' identified by 'admin123';
grant all privileges on *.* to 'sspu'@'%';
flush privileges;
drop database sspudb;
create database sspudb DEFAULT CHARACTER SET UTF8 COLLATE utf8_general_ci;
exit;
mysql -usspu -psspu sspudb
create table sspu_tab1 (id int,name varchar(50));
insert into sspu_tab1 values(5,'wx');
insert into sspu_tab1 values(6,'sspu-com');
insert into sspu_tab1 values(7,'wx-gzh');
insert into sspu_tab1 values(8,'sspu_com');
insert into sspu_tab1 values(9,'oracle');
insert into sspu_tab1 values(10,'mysql');
insert into sspu_tab1 values(11,'sqlserver');
insert into sspu_tab1 values(12,'nosql');

select * from sspu_tab1;
exit;
exit
mysql> select * from sspu_tab1;
+------+--------------------+
| id   | name               |
+------+--------------------+
|    5 | wx                 |
|    6 | sspu-com           |
|    7 | wx-gzh             |
|    8 | sspu_com           |
|    9 | oracle             |
|   10 | mysql              |
|   11 | sqlserver          |
|   12 | nosql              |
+------+--------------------+
15 rows in set (0.00 sec)

ls -lsa /data/lamp/mysql
[root@es1 nginx]# ls -lsa /data/lamp/mysql
total 122952
    4 drwxrwx--- 6 fg   tape     4096 Jul  5 16:47 .
    0 drwxr-xr-x 4 root root       30 Jul  5 16:42 ..
    4 -rw-r----- 1 fg   tape       56 Jul  5 16:42 auto.cnf
    4 -rw------- 1 fg   tape     1676 Jul  5 16:42 ca-key.pem
    4 -rw-r--r-- 1 fg   tape     1112 Jul  5 16:42 ca.pem
    4 -rw-r--r-- 1 fg   tape     1112 Jul  5 16:42 client-cert.pem
    4 -rw------- 1 fg   tape     1676 Jul  5 16:42 client-key.pem
    4 -rw-r----- 1 fg   tape      350 Jul  5 16:42 ib_buffer_pool
12288 -rw-r----- 1 fg   tape 12582912 Jul  5 16:49 ibdata1
49152 -rw-r----- 1 fg   tape 50331648 Jul  5 16:49 ib_logfile0
49152 -rw-r----- 1 fg   tape 50331648 Jul  5 16:42 ib_logfile1
12288 -rw-r----- 1 fg   tape 12582912 Jul  5 16:42 ibtmp1
    4 drwxr-x--- 2 fg   tape     4096 Jul  5 16:42 mysql
   12 drwxr-x--- 2 fg   tape     8192 Jul  5 16:42 performance_schema
    4 -rw------- 1 fg   tape     1680 Jul  5 16:42 private_key.pem
    4 -rw-r--r-- 1 fg   tape      452 Jul  5 16:42 public_key.pem
    4 -rw-r--r-- 1 fg   tape     1112 Jul  5 16:42 server-cert.pem
    4 -rw------- 1 fg   tape     1680 Jul  5 16:42 server-key.pem
    0 drwxr-x--- 2 fg   tape       62 Jul  5 16:48 sspudb
   12 drwxr-x--- 2 fg   tape     8192 Jul  5 16:42 sys

4.访问 phpMyAdmin

Docker-LAMP 预装了phpMyAdmin,
--phpMyAdmin 访问。
http://192.168.1.7/phpmyadmin/
admin admin123

6.访问 httpd 服务。
curl http://192.168.1.7/
[root@es1 app]# curl http://192.168.1.7/
Hello,I'm LAMPll HEI HEI HEIll(::)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值