Docker-Compose部署生产环境


mysql

docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

version: '3'
services:
mysql:
image: mysql
container_name: mysql
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
restart: always
environment:
MYSQL_ROOT_PASSWORD: xxxx #设置root帐号密码
ports:
- 3306:3306
volumes:
- /root/mydata/mysql/data:/var/lib/mysql #数据文件挂载
- /root/mydata/mysql/conf:/etc/mysql/conf.d #配置文件挂载
- /root/mydata/mysql/log:/var/log/mysql #日志文件挂载
networks:
default:
external:
name: mall

手动设置密码

ALTER user 'root'@'localhost' IDENTIFIED BY 'root';

my.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
[client]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld]
default_authentication_plugin=mysql_native_password
character-set-server=utf8mb4
character-set-client-handshake = FALSE
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'

mysql.sh

1
2
3
4
docker stop mysql
docker rm mysql
docker image rm mysql
docker-compose -f docker-compose.yml up -d

给mysql.sh可执行权限

chmod +x mysql.sh

redis

docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
version: '3'
services:
redis:
image: redis
container_name: redis
command: redis-server --appendonly yes --requirepass "xxxx"
restart: always
volumes:
- /root/mydata/redis/data:/data #数据文件挂载
ports:
- 6379:6379
networks:
default:
external:
name: mall

redis.sh

1
2
3
4
docker stop redis
docker rm redis
docker image rm redis
docker-compose -f docker-compose.yml up -d

nginx

docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
version: '3'
services:
nginx:
image: nginx
container_name: nginx
volumes:
- /root/mydata/nginx/conf/nginx.conf:/etc/nginx/nginx.conf #配置文件挂载
- /root/mydata/nginx/html:/usr/share/nginx/html #静态资源根目录挂载
- /root/mydata/nginx/log:/var/log/nginx #日志文件挂载
- /root/mydata/nginx/ssl:/etc/nginx/ssl #ssl证书文件挂载

ports:
- 80:80
- 443:443 #https
restart: always

nginx.sh

1
2
3
4
docker stop nginx
docker rm nginx
docker image rm nginx
docker-compose -f docker-compose.yml up -d

nginx.conf

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
49
50
51
52
53
54
55
56
57
user  nginx;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;

server{
listen 80;
server_name localhost chenlong.site www.chenlong.site

charset utf-8;

location / {
index /blog/index.html;
}
location /blog/ {
root /usr/share/nginx/html;
}
location /blog/img/ {
root /usr/share/nginx/html;
autoindex on;
}
location /blog/css/ {
root /usr/share/nginx/html;
autoindex on;
}
location /blog/js/ {
root /usr/share/nginx/html;
autoindex on;
}
}
}

rabbitmq

docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
version: '3'
services:
rabbitmq:
image: rabbitmq
container_name: rabbitmq
volumes:
- /root/mydata/rabbitmq/data:/var/lib/rabbitmq #数据文件挂载
# - /root/mydata/rabbitmq/log:/var/log/rabbitmq #日志文件挂载
- /root/mydata/rabbitmq/conf/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf
ports:
- 5672:5672
- 15672:15672
restart: always
networks:
default:
external:
name: mall

rabbitmq.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
default_vhost = /
default_user = [默认账户名称]
default_pass = [默认账户密码]
# 运行 root 账号进行远程访问
loopback_users.[默认账户名称] = none
# 设置 root 账户的标签
default_user_tags.administrator = true
# 设置 root 账号的权限
default_permissions.configure = .*
default_permissions.read = .*
default_permissions.write = .*
# 设置默认端口
listeners.tcp.default = 5672

rabbitmq.sh

1
2
3
4
docker stop rabbitmq
docker rm rabbitmq
docker image rm rabbitmq:management
docker-compose -f docker-compose.yml up -d
  • 启动完成后进入localhost:15672配置虚拟主机

← Prev SpringDataJPA整合Querydsl & JPA实体类使用Auditing | Spring AOP实现接口日志 Next →