0%

docker的应用

docker 配置运行nginx

1
2
3
4
5
6
7
8
9
10

docker-compose -f nginx.yml up -d
内容如下:
nginx:
image: nginx:latest
ports:
- "8082:83"
volumes:
- ./nginx/www:/usr/share/nginx/html
- ./nginx/conf/default.conf:/etc/nginx/conf.d/default.conf

docker 配置运行mysql,mongo,redis

docker-compose -f docker-compose.yml up -d

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
version: "3.7"
services:
mongo:
image: mongo:latest
ports:
- "27017:27017"
volumes:
- ./mongo:/data/db
redis:
image: redis:latest
ports:
- "6379:6379"
mysql:
image: mysql:latest
volumes:
- ./mysql:/var/lib/mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: "root"

在centos上安装docker

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// 卸载残留
sudo yum remove docker docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine


sudo yum remove docker-ce docker-ce-cli containerd.io
// 设置仓库
先安装依赖包
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2

// 添加稳定仓库
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
// 安装 docker
sudo yum install docker-ce docker-ce-cli containerd.io
//启动
sudo systemctl start docker


// 因为原目录空间不大,所以在空间大的磁盘创建目录

mkdir /data/docker

mkdir /etc/systemd/system/docker.service.d

vi /etc/systemd/system/docker.service.d/devicemapper.conf

// 写入内容

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --graph=/data/docker

// 重启docker

systemctl daemon-reload
systemctl restart docker
//设置docker开机自启
systemctl enable docker
// 确定没问题后,删除原目录 rm -rf /var/lib/docker

在centos上安装 docker-compose

1
2
3
4
5
6
7
 curl -L https://github.com/docker/compose/releases/download/1.24.0-rc1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

// 设置docker-compose可执行
sudo chmod +x /usr/local/bin/docker-compose

// 查看docker-compose是否安装成功
docker-compose --version

-------------本文结束感谢你的阅读---------