问题描述
使用docker启动容器时遇到报错,如下:
ERROR: Unexpected bus error encountered in worker. This might be caused by insufficient shared memory (shm).
问题分析
此问题是由于容器共享内存不足导致,可以通过启动容器指定参数或修改docker默认配置来修改shm大小。默认shm大小为 64MiB。
问题解决
方案一
启动容器指定 --shm-size 参数
# 启动容器
$ docker run -d -p 80:80 --shm-size 1g nginx
9f6b2c6c6d27c0b07e536fc52acd646e6d05c5b0709f2ff2382f156464e0977a
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9f6b2c6c6d27 nginx "/docker-entrypoint.…" 3 seconds ago Up 3 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp loving_galois
# 验证
$ docker inspect 9f6b2c6c6d27 |grep -i shm
"ShmSize": 1073741824,
方案二
修改docker配置文件
$ cat /etc/docker/daemon.json
{
"default-shm-size": "64M"
}
$ systemctl reload docker
$ docker run -d -p 80:80 --name shm-test ngin
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f48a40f310ed nginx "/docker-entrypoint.…" 3 seconds ago Up 3 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp shm-test
$ docker inspect f48a40f310ed |grep -i shm
"Name": "/shm-test",
"ShmSize": 1073741824,
参考链接
[1] https://docs.docker.com/engine/reference/commandline/dockerd/ [2] https://docs.docker.com/engine/reference/commandline/run/ 如果您有其他问题,欢迎您联系火山引擎技术支持服务