(1)准备依赖的镜像,包括mariadb、jdk1.8、nginx,配置docker-compose.yml文件
services:mariadb:image: mariadbports:- "3314:3306"environment:- MARIADB_ROOT_PASSWORD=123456volumes:- ./mysql:/var/lib/mysqlnetworks:- qingpudispatch:image: jdk1.8:1.0ports:- "1234:8080"volumes:- ./dispatch/application.properties:/home/application.properties- ./dispatch/application-test.properties:/home/application-test.properties- ./dispatch/dispatch-0.0.1.jar:/home/dispatch-0.0.1.jar- ./dispatch/logback-plus.xml:/home/logback-plus.xml- ./dispatch/logs:/home/logsworking_dir: /homedepends_on:- mariadbcommand: java -jar dispatch-0.0.1.jarnetworks:- qingpunginx:image: nginxvolumes:- ./nginx/nginx.conf:/etc/nginx/nginx.conf- ./nginx/default.conf:/etc/nginx/conf.d/default.conf- ./nginx/html:/home/htmldepends_on:- dispatchports:- "82:80"networks:- qingpu
networks:qingpu: {}
其中mariadb是关系型数据库,dispatch是java可执行jar包,nginx是web服务器,目录结构如下
(2)构建、运行容器,查询容器,查看进程
PS E:\docker\qingpu> docker-compose up -d
[+] Running 4/4- Network qingpu_qingpu Created 0.1s- Container qingpu-mariadb-1 Started 1.2s- Container qingpu-dispatch-1 Started 1.6s- Container qingpu-nginx-1 Started 2.2s
PS E:\docker\qingpu> docker-compose top
qingpu-dispatch-1
UID PID PPID C STIME TTY TIME CMD
root 4160 4135 99 05:48 ? 00:00:09 java -jar dispatch-0.0.1.jarqingpu-mariadb-1
UID PID PPID C STIME TTY TIME CMD
999 4059 4038 7 05:48 ? 00:00:00 mariadbdqingpu-nginx-1
UID PID PPID C STIME TTY TIME CMD
root 4304 4280 1 05:48 ? 00:00:00 nginx: master process nginx -g daemon off;
uuidd 4381 4304 0 05:48 ? 00:00:00 nginx: worker process
uuidd 4382 4304 0 05:48 ? 00:00:00 nginx: worker process
uuidd 4383 4304 0 05:48 ? 00:00:00 nginx: worker process
uuidd 4384 4304 0 05:48 ? 00:00:00 nginx: worker processPS E:\docker\qingpu> docker-compose ps
NAME COMMAND SERVICE STATUS PORTS
qingpu-dispatch-1 "java -jar dispatch-…" dispatch running 0.0.0.0:1234->8080/tcp
qingpu-mariadb-1 "docker-entrypoint.s…" mariadb running 0.0.0.0:3314->3306/tcp
qingpu-nginx-1 "/docker-entrypoint.…" nginx running 0.0.0.0:82->80/tcp
PS E:\docker\qingpu>