Docker 常见问题

1. 使用Dockerfile构建镜像时报错

ERROR: Failed to create lib/ld-musl-x86_64.so.1: No space left on device ERROR: musl-1.1.15-r6: No space left on device

Dockerfile内容如下:


FROM alpine 
RUN apk update && apk upgrade 
RUN apk add python 
RUN apk add curl 
RUN apk add libsodium 
RUN curl "https://bootstrap.pypa.io/get-pip.py" -o "/tmp/get-pip.py" 
RUN python "/tmp/get-pip.py" 
RUN pip install --upgrade pip 
RUN pip install shadowsocks 
ENV SS_PASSWORD 123456 
ENV SS_METHOD chacha20
COPY ss.cfg /tmp/ 
ENTRYPOINT /usr/bin/ssserver -k ${SS_PASSWORD} -m ${SS_METHOD} 
EXPOSE 60000

经查证排除磁盘空间不足的问题。
这个问题是apk的一个bug。
参考连接:
https://github.com/gliderlabs/docker-alpine/issues/231

2. Docker时区问题
容器镜像中一般默认时区是UTC,改为CST可以如下进行:
(1)方法一:
起容器时加上 -v /etc/loaltime:/etc/loaltime:ro #共享宿主机时区

(2) 方法二


   cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 
 

3. 启动Docker进程失败–Centos7.X

报错如下:

[root@centos72 ~]# systemctl start docker
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.

ifconfig查看时没有生成docker0网桥
查看状态报错信息如下:

[root@centos72 ~]# systemctl status docker.service
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Mon 2017-03-06 10:57:41 CST; 10s ago
     Docs: http://docs.docker.com
  Process: 48584 ExecStart=/usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current $OPTIONS $DOCKER_SE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY (code=exited, status=1/FAILURE)
 Main PID: 48584 (code=exited, status=1/FAILURE)

Mar 06 10:57:41 centos72.novalocal dockerd-current[48584]: time="2017-03-06T10:57:41.033103724+08:00" level=warning msg="Docker could not enable SELinux on the host system"
Mar 06 10:57:41 centos72.novalocal dockerd-current[48584]: time="2017-03-06T10:57:41.038337006+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"
Mar 06 10:57:41 centos72.novalocal dockerd-current[48584]: time="2017-03-06T10:57:41.038541983+08:00" level=warning msg="mountpoint for pids not found"
Mar 06 10:57:41 centos72.novalocal dockerd-current[48584]: time="2017-03-06T10:57:41.038684660+08:00" level=info msg="Loading containers: start."
Mar 06 10:57:41 centos72.novalocal dockerd-current[48584]: time="2017-03-06T10:57:41.043425594+08:00" level=info msg="Firewalld running: false"
Mar 06 10:57:41 centos72.novalocal dockerd-current[48584]: time="2017-03-06T10:57:41.111389603+08:00" level=fatal msg="Error starting daemon: Error initializing network controller: Error creating default \"bridge\" network: failed to parse pool request for address spa
Mar 06 10:57:41 centos72.novalocal systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Mar 06 10:57:41 centos72.novalocal systemd[1]: Failed to start Docker Application Container Engine.
Mar 06 10:57:41 centos72.novalocal systemd[1]: Unit docker.service entered failed state.
Mar 06 10:57:41 centos72.novalocal systemd[1]: docker.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
You have new mail in /var/spool/mail/root

关键内容:

level=fatal msg="Error starting daemon: Error initializing network controller: Error creating default “bridge” network: failed to parse pool request for address spa

解决:
在Docker配置文件/etc/sysconfig/docker "OPTIONS"中加入:–bip=172.17.42.1/16, 如下:

# Modify these options if you want to change the way the docker daemon runs
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false --bip=172.17.42.1/16'

systemctl start docker即可

4. docker启动失败

[root@localhost ~]# systemctl status docker.service -l
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sat 2017-03-18 01:10:06 PDT; 2min 53s ago
     Docs: http://docs.docker.com
  Process: 3494 ExecStart=/usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY (code=exited, status=1/FAILURE)
 Main PID: 3494 (code=exited, status=1/FAILURE)

Mar 18 01:10:04 localhost.localdomain systemd[1]: Starting Docker Application Container Engine...
Mar 18 01:10:04 localhost.localdomain dockerd-current[3494]: time="2017-03-18T01:10:04.976205048-07:00" level=info msg="libcontainerd: new containerd process, pid: 3500"
Mar 18 01:10:06 localhost.localdomain dockerd-current[3494]: time="2017-03-18T01:10:06.011206081-07:00" level=warning msg="devmapper: Usage of loopback devices is strongly discouraged for production use. Please use `--storage-opt dm.thinpooldev` or use `man docker` to refer to dm.thinpooldev section."
Mar 18 01:10:06 localhost.localdomain dockerd-current[3494]: time="2017-03-18T01:10:06.022012288-07:00" level=warning msg="devmapper: Base device already exists and has filesystem xfs on it. User specified filesystem  will be ignored."
Mar 18 01:10:06 localhost.localdomain dockerd-current[3494]: time="2017-03-18T01:10:06.027998073-07:00" level=fatal msg="Error starting daemon: error initializing graphdriver: \"/var/lib/docker\" contains several valid graphdrivers: devicemapper, overlay; Please cleanup or explicitly choose storage driver (-s <DRIVER>)"
Mar 18 01:10:06 localhost.localdomain systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Mar 18 01:10:06 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.
Mar 18 01:10:06 localhost.localdomain systemd[1]: Unit docker.service entered failed state.
Mar 18 01:10:06 localhost.localdomain systemd[1]: docker.service failed.

关键内容:
level=fatal msg=“Error starting daemon: error initializing graphdriver: “/var/lib/docker” contains several valid graphdrivers: devicemapper, overlay; Please cleanup or explicitly choose storage driver (-s )”

解决:
删除/var/lib/docker/下面的数据,重启docker服务即可,重启后/var/lib/docker/里面的数据会重新生成。

rm -rf /var/lib/docker/*
systemctl start docker

5. Docker启动失败–ubuntu
启动docker时报错如下:


Error initializing network controller: list bridge addresses failed: no available network

解决:


apt-get install bridge-utils
brctl addbr docker0
ifconfig docker0 172.17.42.1 
echo 'DOCKER_OPTS="b=docker0"' >> /etc/default/docker
systemctl docker start

6. docker pull镜像失败
具体报错如下:

[root@localhost ~]# docker pull hub.c.163.com/xxxxxx/test:python
Trying to pull repository hub.c.163.com/xxxxxx/test ... 
Pulling repository hub.c.163.com/xxxxxx/test
Error: image xxxxxx/test not found

如果镜像存在且路径正确,一般是未登陆认证的原因,docker login hub.c.163.com 后可以解决。
7. unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives don’t match

启动 docker 时报错,journalctl -xe 结果如下:

在这里插入图片描述

解决:
备份文件/etc/docker/daemon.json,将此文件内容置为:
{ }
重启 docker 服务。

8. 二进制安装docker,启动时报错
journalctl -xe 查看到信息:

/usr/bin/dockerd: error while loading shared libraries: libseccomp.so.2: cannot open shared
解决:

yum -y install libseccomp

9.中文文件名皆显示为问号
解决:

localedef -i zh_CN -f UTF-8 zh_CN.UTF-8  
yum -y install kde-l10n-Chinese && yum -y reinstall glibc-common   
localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
# 永久解决建议在Dockerfile中加ENV 环境变量   
export LC_ALL=zh_CN.utf8  

9. Docker 重启报错
journalctl -fu docker 报错信息包含如下信息:

level=error msg="containerd: notify OOM events" error="open /proc/15786/cgroup: no such file or directory"
level=fatal msg="open /var/run/docker/libcontainerd/containerd/xxxxx/xxxxx/process.json: no such file or directory"

分析:某个容器的资源没有清理干净导致docker 重启失败
解决:删除异常容器的数据,然后重启Docker,删除前备份下容器的数据。

 /var/run/docker/libcontainerd/containerd/
 mv 异常容器的目录  备份路径
 systemctl restart docker

10.Docker 启动报错
journalctl -xe 报selinux相关的错误,导致docker 服务无法启动。
解决:/etc/selinux/config中关掉selinux,重启服务器。

11. http: server gave HTTP response to HTTPS client
分析:Docker 拉镜像默认走https,registry提供的方式为http
解决:新建文件/etc/docker/daemon.json,加入insecure配置:

{
    "insecure-registries": [
        "test.docker.jiankunking.io:5000", 
        "hub.docker.jiankunking.io:5000"
    ]
}
# 重启Docker 服务
systemctl restart docker 

12. Docker 启动失败

journalctl -xe 查看报错如下:

Error starting daemon: SELinux is not supported with the overlay2 graph driver on this kernel. 

解决:
修改docker 配置文件:/etc/sysconfig/docker,将selinux配置去掉:

 --selinux-enabled

重启docker。

系列视频课程正在陆续上线,课程中会提供视频中涉及的操作文档、软件包,系列课程内容更加完整、贴近实际工作。欢迎感兴趣的小伙伴到网易云课堂进行学习。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值