Copy #jenkins的数据目录
$ mkdir -p /mount/jenkins/
#maven本地仓库地址
$ mkdir -p /mount/maven/repository
Copy $ mkdir -p /mount/mysql/data \
-p /mount/mysql/conf.d \
-p /mount/mysql/log
说明: 最新官方MySQL(5.7.19)的docker镜像在创建时映射的配置文件目录有所不同 MySQL(5.7.19)的默认配置文件是 /etc/mysql/my.cnf
文件。如果想要自定义配置, 建议向 /etc/mysql/conf.d
目录中创建 *.cnf
文件。新建的文件可以任意起名,只要保证后缀名是 cnf 即可。 新建的文件中的配置项可以覆盖 /etc/mysql/my.cnf
中的配置项。 又由于宿主主机 /mount/mysql/conf.d
目录 已经挂载到docker容器 /etc/mysql/conf.d
目录,所以只需在 /mount/mysql/conf.d
目录下自定义*.cnf文件即可生效。
Copy $ mkdir -p /mount/nginx/conf \
-p /mount/nginx/logs \
-p /mount/nginx/html \
-p /mount/nginx/conf.d
说明: 映射的配置文件一定要存在,否则启动服务会报错
Copy $ mkdir -p /mount/redis/data
Copy version: '3'
services:
jenkins:
image: jenkins/jenkins:lts
container_name: jenkins
user: root
privileged: true
restart: always
environment:
JAVA_OPTS: '-Djava.util.logging.config.file=/var/jenkins_home/log.properties'
volumes:
- /mount/jenkins/:/var/jenkins_home
- /usr/local/apache-maven-3.8.6:/usr/local/apache-maven-3.8.6
- /mount/maven/repository:/mount/maven/repository
- /usr/local/java/jdk1.8.0_341:/usr/local/java/jdk1.8.0_341
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker
- /usr/lib/x86_64-linux-gnu/libltdl.so.7:/usr/lib/x86_64-linux-gnu/libltdl.so.7
ports:
- 8088:8080
expose:
- 8080
- 50000
nginx:
image: nginx:latest
container_name: nginx
restart: always
volumes:
- /mount/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
- /mount/nginx/html:/usr/share/nginx/html
- /mount/nginx/logs:/var/log/nginx
- /mount/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf
ports:
- 80:80
redis:
image: redis:latest
container_name: redis
command: redis-server --appendonly yes --requirepass '123456'
restart: always
volumes:
- /mount/redis/data:/data
ports:
- 6379:6379
mysql:
image: mysql:5.7
container_name: mysql
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
volumes:
- /mount/mysql/data:/var/lib/mysql
- /mount/mysql/conf.d:/etc/mysql/conf.d
- /mount/mysql/log:/var/log/mysql
Copy $ cd /mount
$ docker-compose up -d #后台运行
[+] Running 4/4
⠿ Container nginx Started 2.6s
⠿ Container redis Started 2.6s
⠿ Container mysql Started 2.7s
⠿ Container jenkins Started 2.6s