1. 安装docker
查看系统的版本
cat /etc/redhat-release
Docker CE 支持 64 位版本 CentOS 7 ,并且要求内核版本不低于 3.10。 CentOS 7 满足最低内核的要求。
安装docker前先更新下,免得出错
yum update -y
reboot
安装docker
yum install -y docker
docker version # 查看docker版本
启动
systemctl start docker # 启动
systemctl enable docker # 添加入开机启动
2. LAMP环境搭建方案
搭建LAMP环境的主要方案分别是:
一个镜像直接包含全部(简单才是最好用的)
apache、mysql、php独立连接。
虽然只是了两种方案,但是细节处还是有所不同的。比如说:直接下载别人做好的镜像或者是自己建模,自己建模也分yum安装,源码安装,然后还可以根据个人习惯优化和服务配置。这里列举最简单的方案。
docker search -s 10 lamp # 搜索被收藏或使用较多的LAMP镜像,小伙伴们都推荐使用tutum/lamp
docker pull docker.io/tutum/lamp #下载镜像
docker images #查看镜像
3. 创建LAMP容器
mkdir /mysql_data
docker run -d --name=lamp -p 8080:80 -p 3306:3306 -v /mysql_data:/var/lib/mysql docker.io/tutum/lamp
将宿主机的目录“/mysql_data”映射到容器的“/var/lib/mysql”目录。这是因为默认情况下数据库的数据库文件和日志文件都会存放于容器的AUFS文件层,这不仅不使得容器变得越来越臃肿,不便于迁移、备份等管理,而且数据库的性能也会受到影响。因此建议挂载到宿主机的目录到容器内。
接下来进入容器
docker exec -it lamp /bin/bash
mysql_secure_installation //初始化数据库
按下enter键你会看见结尾如下的对话。
1.Enter current password for root (enter for none): <–初次运行直接回车
2.Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
3.New password: <– 设置root用户的密码
4.Re-enter new password: <– 再输入一次你设置的密码
5.Remove anonymous uclear
6.sers? [Y/n] <– 是否删除匿名用户,回车
7.Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车
8.Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车
9.Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车
10.All done! If you’ve completed all of the above steps, your MariaDB
11.installation should now be secure.
Thanks for using MariaDB!
进入mysql
1.mysql –u root -p"自己的数据库密码"
2.create database wp; #创建数据库
3.\q # 退出mysql
如果你使用的是云服务器,只要将你的项目导入即可,至于详细设置不同云网站有所不同
1.apt update
2.cd /var/www/html