docker-compose快速搭建lnmp+redis服务器环境

时间:2023-04-22 09:39:56

因为我用的是MacOS

安装docker

sudo yum update
sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
sudo yum install docker-engine
sudo service docker start

安装docker-compose

先安装pip

sudo yum update
sudo yum -y install epel-release
sudo yum -y install python-pip

再通过pip安装docker-compose

sudo pip install -U docker-compose

Finish !

搭建lnmp7+redis+memcache环境

生成目录结构

在根目录下创建一个green目录
然后在green目录下生成nginx php mysql redis memcahe子目录,用于存放各类数据

sudo mkdir green

目录如下:

docker-compose快速搭建lnmp+redis服务器环境

利用docker-compose生成环境

创建 docker-compose.yml

  1 nginx-php:
2 build: ./nginx-php
3 ports:
4 - "80:80"
5 links:
6 - "mysql"
7 volumes:
8 - /green/www:/var/www/html
9 environment:
10 WEB_DOCUMENT_ROOT: /var/www/html
11 mysql:
12 build: ./mysql
13 ports:
14 - "3306:3306"
15 volumes:
16 - /green/mysql/data:/var/lib/mysql
17 environment:
18 MYSQL_ROOT_PASSWORD: root
19 redis:
20 build: ./redis
21 ports:
22 - "6379:6379"
23 volumes:
24 - /green/redis/data:/data
25 memcache:
26 build:./memcache
27 ports:
28 - "11211:11211"
29 volumes:
30 - /green/redis/data:/data

最后运行命令

cd /green
docker-compose up -d

最后的下载过程

自动生成容器过程

docker-compose快速搭建lnmp+redis服务器环境