一、docker搭建lamp:192.168.98.136
1、关闭防火墙,安装docker
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum -y install docker
2、docker加速
[root@localhost ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://yol1de5p.mirror.aliyuncs.com"]
}
3、启动docker
[root@localhost ~]# systemctl start docker
4、拉取MySQL镜像
[root@localhost ~]# docker pull mysql
5、拉取php:7.2-apache镜像
[root@localhost ~]# docker pull php:7.2-apache
6、查看镜像
docker images
7、创建网络
docker network create lamp
8、查看网络
docker network ls
9、创建生成mysql和php容器的脚本
vim docker_lamp.sh
#!/bin/bash
function mysql()
{
docker run --name mysql --net lamp -p 3306:3306 \
-v /data/docker/mysql/data:/var/lib/mysql \
-v /data/docker/mysql/conf:/etc/mysql/conf.d \
-v /data/docker/mysql/logs:/logs \
-e MYSQL_ROOT_PASSWORD=Test1234 \
-d mysql:latest --character-set-server=utf8
}
function httpd_php()
{
docker run --name httpd-php --net lamp -p 80:80 \
-v /data/docker/httpd/conf:/etc/apache2/sites-enabled \
-v /data/docker/www:/var/www/html \
-v /data/docker/httpd/logs:/var/log/apache2 \
-d php:7.2-apache
}
$1
10、启动mysql和php容器
[root@localhost ~]# sh docker_lamp.sh mysql
c280ef3cf48a4d660efd8d2187d2e458b10f9b33540047345c1bd40a70bab138
[root@localhost ~]# sh docker_lamp.sh httpd_php
92ceab514f98305c4246e42a2303b97f7fc951b5fa56863d75b615b50e967671
11、查看容器
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
92ceab514f98 php:7.2-apache "docker-php-entryp..." About a minute ago Up About a minute 0.0.0.0:80->80/tcp httpd-php
c280ef3cf48a mysql:latest "docker-entrypoint..." About a minute ago Up About a minute 0.0