运行mysql

1
2
3
4
5
6
docker run --name mysql \
-v /usr/local/mysql/data:/var/lib/mysql \
-v /usr/local/mysql:/etc/mysql/conf.d \
-v /usr/local/mysql/log:/var/log/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-p 3306:3306 -d mysql:5.7.25

运行redis

1
2
3
4
5
6
7
8
9
docker run --name redis  \
-v /usr/local/redis/data:/data \
-v /usr/local/redis/redis.conf:/usr/local/etc/redis/redis.conf \
-p 6379:6379 -d redis:latest

docker run --name redis \
-v /home/redis/data:/data \
-v /home/redis/redis.conf:/usr/local/etc/redis/redis.conf \
-p 6379:6379 -d redis:latest

运行rabbitmq

1
2
3
4
docker run --name rabbitmq1 \
-dp 5672:5672 \
-p 15672:15672 \
rabbitmq:3-management

打包运行后端服务

1
2
3
4
FROM openjdk:8u102
COPY education-api.jar .
CMD java -jar -Dspring.profiles.active=prod education-api.jar
EXPOSE 8001
1
docker build -t education-api:1.0 .
1
docker run --name education-api -dp 8001:8001 education-api:1.0

运行nginx

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
worker_processes  1;

events {
worker_connections 1024;
}


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

sendfile on;


keepalive_timeout 65;

server {
listen 80;
server_name localhost;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
docker run --name nginx1 \
-dp 80:80 \
-v /usr/local/nginx/html:/usr/share/nginx/html \
-v /usr/local/nginx/nginx.conf:/etc/nginx/nginx.conf \
nginx

docker run --name nginx \
-dp 8008:8008 \
-p 8009:8009 \
-p 8010:8010 \
-p 8011:8011 \
-p 8012:8012 \
-v /home/webapps:/home/webapps \
-v /home/nginx/nginx.conf:/etc/nginx/nginx.conf \
nginx

容器编排

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
services:
education-api:
build: ./
image: education-api:1.0
container_name: education-api
ports:
- 8001:8001
depends_on:
- mymysql
- myredis
- myrabbitmq
- mynginx
mymysql:
image: mysql:5.7.25
container_name: mysql1
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
volumes:
- /usr/local/mysql/data:/var/lib/mysql
- /usr/local/mysql:/etc/mysql/conf.d
- /usr/local/mysql/log:/var/log/mysql
myredis:
image: redis:latest
container_name: redis1
ports:
- 6379:6379
volumes:
- /usr/local/redis/data:/data
- /usr/local/redis/redis.conf:/usr/local/etc/redis/redis.conf
myrabbitmq:
image: rabbitmq:3-management
container_name: rabbitmq1
ports:
- 5672:5672
- 15672:15672
mynginx:
image: nginx:latest
container_name: nginx1
ports:
- 80:80
volumes:
- /usr/local/nginx/html:/usr/share/nginx/html
- /usr/local/nginx/nginx.conf:/etc/nginx/nginx.conf
privileged: true

docker up -d