首页 > 其他 > 详细

通过docker安装一个LAMP架构

时间:2020-11-15 00:22:10      阅读:43      评论:0      收藏:0      [点我收藏+]

1、通过 RPM 安装 docker 17.03.0 版本并且配置 docker 阿里加速

[root@centos7 ~]#wget -P /etc/yum.repos.d/ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

[root@centos7 ~]#yum install -y --setopt=obsoletes=0 docker-ce-17.03.1.ce-1.el7.centos docker-ce-selinux-17.03.1.ce-1.el7.centos

[root@centos7 ~]#systemctl enable --now docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@centos7 ~]#docker version
Client:
Version: 17.03.1-ce
API version: 1.27
Go version: go1.7.5
Git commit: c6d412e
Built: Mon Mar 27 17:05:44 2017
OS/Arch: linux/amd64

Server:
Version: 17.03.1-ce
API version: 1.27 (minimum version 1.12)
Go version: go1.7.5
Git commit: c6d412e
Built: Mon Mar 27 17:05:44 2017
OS/Arch: linux/amd64
Experimental: false

[root@centos7 ~]#mkdir -p /etc/docker
[root@centos7 ~]#tee /etc/docker/daemon.json <<EOF
> {
> "registry-mirrors":["https://fof8w27e.mirror.aliyuncs.com"]
> }
> EOF
[root@centos7 ~]#systemctl daemon-reload
[root@centos7 ~]#systemctl restart docker

 

2、通过 docker 安装一个 LAPM 架构

[root@centos7 ~]#docker search -s 10 lamp
Flag --stars has been deprecated, use --filter=stars=3 instead
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mattrayner/lamp A simple LAMP docker image running the pre... 240 [OK]
linode/lamp LAMP on Ubuntu 14.04.1 LTS Container 178
tutum/lamp Out-of-the-box LAMP image (PHP+MySQL) 141
greyltc/lamp a super secure, up-to-date and lightweight... 100 [OK]
fauria/lamp Modern, developer friendly LAMP stack. Inc... 93 [OK]
lioshi/lamp Docker image for LAMP under debian 15 [OK]
dgraziotin/lamp 11 [OK]
[root@centos7 ~]#docker pull mattrayner/lamp
[root@centos7 ~]#docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mattrayner/lamp latest 05750cfa54d5 3 months ago 915 MB
[root@centos7 ~]#mkdir /mysql_data
[root@centos7 ~]#docker run -d --name=lamp -p 80:80 -p 3306:3306 -v /mysql_data:/var/lib/mysql docker.io/mattrayner/lamp

[root@centos7 ~]#docker exec -it lamp bash
root@f7abb18696ca:/# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y 

There are three levels of password validation policy:

LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file 

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
New password: 

Re-enter new password:

Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y 
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) :y 

Normally, root should only be allowed to connect from
‘localhost‘. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y

... skipping.
By default, MySQL comes with a database named ‘test‘ that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) :y 
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) :y 

All done!

该镜像是基于ubuntu1804系统的

查看php mysql apache都是哪个版本

root@f7abb18696ca:~# dpkg -l
得知

php7.4 MySQL5.7.30 apache2.4.29

下载个包查看端口信息

root@f7abb18696ca:/# apt-get install net-tools
查看端口

root@f7abb18696ca:/# netstat -aptn
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 504/apache2

root@f7abb18696ca:~# cd /var/www/html/
root@f7abb18696ca:/var/www/html# vim index.php

<?php
echo phpinfo();
?>

3、写出 docker run 命令的延申指令,如怎么在停止一个 docker 容器的时候自动删除该容器

[root@centos7 ~]#docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@centos7 ~]#docker run -it --rm centos bash
[root@719deb51f412 /]# exit
exit
[root@centos7 ~]#docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES


4、写出 docker run 命令在自动启动 docker 服务时通过什么参数能够启动 docker 中的容器,从而实现容器随着 docker 服务的启动而自动启动

[root@centos7 ~]#docker run -d --name centos1 --restart=always centos

通过docker安装一个LAMP架构

原文:https://www.cnblogs.com/zh2020tz/p/13975170.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!