目录结构
Dockerfile
FROM java:8
MAINTAINER wgq
VOLUME /logs
COPY lib lib
COPY config config
ADD server.jar app.jar
ENV JAVA_OPTS="-server -XX:+UseG1GC -Xmx2048m -Xms2048m -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMPercentage=70.0 -XX:NewRatio=2 -XX:+PrintGCDetails -XX:+PrintHeapAtGC -Xloggc:/logs/gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/logs/heapdump.hprof"
ENTRYPOINT ["java","-jar","/app.jar"]
docker-compose.yml
version: '3'
services:
game:
build: .
depends_on:
- redis
- mysql
- mongo
ports:
- 8587:8586
privileged: true
volumes:
- /home/game/config:/config
- /home/game/logs:/logs
redis:
container_name: redis1
image: redis
restart: always
ports:
- 10010:6379
volumes:
- /home/redis/data:/data:rw
environment:
- TZ=Asia/Shanghai
command: ["redis-server", "--appendonly", "yes", "--requirepass",""]
deploy:
resources:
limits:
memory: 500M # 最大内存
reservations:
memory: 256M # 最小内存
mysql:
container_name: mysql1
image: mysql:5.7
restart: always
privileged: true
environment:
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: "123456"
ports:
- 10011:3306
volumes:
- /home/mysql/data:/var/lib/mysql
- /home/mysql/conf:/etc/mysql/
- /home/mysql/log:/var/log/mysql
- /home/config/init.sql:/docker-entrypoint-initdb.d/init.sql
mongo:
container_name: mongo1
image: mongo:5.0
restart: always
ports:
- 10012:27017
volumes:
- /home/mongo/db:/data/db
deploy:
resources:
limits:
memory: 500M # 最大内存
reservations:
memory: 256M # 最小内存
run.sh run.bat
docker-compose down
docker-compose up -d
错误信息
使用docker-compose 部署 mysql5.7 时报错
[Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started.
[ERROR] [Entrypoint]: mysqld failed while attempting to check config
mysql command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.yaxDKXjtm0
解决方法:
1. 我在 mysql 中设置了内存限制
deploy:
resources:
limits:
memory: 500M # 最大内存
reservations:
memory: 256M # 最小内存
把这个移除
2. 添加 privileged: true 参数
3. 添加
volumes:
- /home/mysql/conf:/etc/mysql/
错误信息2
library initialization failed - unable to allocate file descriptor table - out of memory#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f863a827532, pid=1, tid=0x00007f860785f700
#
# JRE version: OpenJDK Runtime Environment (8.0_111-b14) (build 1.8.0_111-8u111-b14-2~bpo8+1-b14)
# Java VM: OpenJDK 64-Bit Server VM (25.111-b14 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libc.so.6+0x36532] abort+0x232
#
# Core dump written. Default location: //core or core.1
#
# An error report file with more information is saved as:
# //hs_err_pid1.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
[error occurred during error reporting , id 0xb]
.......
[Too many errors, abort]
.......
解决方案。
library initialization failed - unable to allocate file descriptor table - out of memory 问题处理
1、修改docker服务启动配置文件
# vim /usr/lib/systemd/system/docker.service
...
[Service]
...
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --default-ulimit nofile=65536:65536 #第13行
...
2、重新加载配置
systemctl daemon-reload
systemctl restart docker