有时候做测试环境需要快速安装lamp,我们看看怎么进行
1) 首先看看有哪些lamp的包没有,使用docker search lamp
[root@localhost ~]# docker search lamp
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mattrayner/lamp A simple LAMP docker image running the prere鈥 229 [OK]
linode/lamp LAMP on Ubuntu 14.04.1 LTS Container 178
tutum/lamp Out-of-the-box LAMP image (PHP+MySQL) 139
greyltc/lamp a super secure, up-to-date and lightweight L鈥 101 [OK]
......
我们看到第一个是lamp,下载还比较多。下载一个最多的mattrayner/lamp,当然,要自己做的dockerfile安装也是可以的。
[root@localhost ~]# docker pull mattrayner/lamp
Using default tag: latest
latest: Pulling from mattrayner/lamp
c64513b74145: Pull complete
01b8b12bad90: Pull complete
c5d85cf7a05f: Pull complete
b6b268720157: Pull complete
.....
Digest: sha256:bf1ca644324b0fcfc589e6696ce673397853afc6ba665a8d3e4c4c89888c3fb6
Status: Downloaded newer image for mattrayner/lamp:latest
docker.io/mattrayner/lamp:lates
使用inspect 功能查看mattrayner的开放端口。
[root@localhost ~]# docker inspect /mattrayner/lamp
[
{
"Id": "sha256:05750cfa54d5c07510961007006dfaae6849739487a550e6d7588c9b550625cb",
"RepoTags": [
"mattrayner/lamp:latest"
],
"RepoDigests": [
"mattrayner/lamp@sha256:bf1ca644324b0fcfc589e6696ce673397853afc6ba665a8d3e4c4c89888c3fb6"
],
"Parent": "",
"Comment": "",
"Created": "2020-07-21T07:54:20.497204047Z",
"Container": "46418263e4d6cf86d06a1aef5c8e1d7354438c6ccd9024b5f264eab12c4d7e54",
"ContainerConfig": {
"Hostname": "46418263e4d6",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"3306/tcp": {},
"80/tcp": {}
},
"Tty": false,
------------
看到端口需要开放3306和80端口,因为在其他的使用过程中我们可能还需要使用mysql做实验,因此同时开放3306端口,将来还能继续使用。
启用名字dklamp,以便以后可以直接使用名字重启,将80口映射到主机的8081, -d表示后台运行
[root@localhost ~]# docker run --name dklamp -p 8081:80 -p 3306:3306 -d mattrayner/lamp
fffc1d9ba4fecad88b74b04bc8cd873eecd080a71a1fe158c83da04ebd4ed98e
测试运行结果
查看dklamp中的mysql的root密码,使用命令
[root@localhost ~]# docker logs dklamp
Updating for PHP 7.4
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 IK0eY3XvOMdF
mysql -uadmin -pIK0eY3XvOMdF -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!
查到密码为 IK0eY3XvOMdF,用户名为admin
[root@localhost ~]# mysql -uadmin -pIK0eY3XvOMdF -h127.0.0.1
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 25
Server version: 5.7.30-0ubuntu0.18.04.1-log (Ubuntu)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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> exit
可以看到登录成功