Docker容器在运行时立即退出

时间:2018-06-09 11:29:09

标签: linux embedded-linux docker-watchtower

我在raspberry pi零上运行docker,我在启动时使用systemd启动了watchtower和我的容器。我的容器它只是工作,如果我用我的手运行它或在启动时由systemd运行但当我推新图像我的私人repo了望塔检测新版本..停止,删除并尝试运行新版本但此时容器退出与137立即(运行3秒后)。

这是退出容器的日志:

pi@raspberrypi:~ $ sudo docker logs 6f2a4282cdfe
Systemd init system enabled.
systemd 215 running in system mode. (+PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR)
Detected virtualization 'other'.
Detected architecture 'arm'.
Set hostname to <fc6cd3bd9174>.
Failed to configure loopback device: Permission denied
Received SIGRTMIN+3.

这是inspect命令的结果:

[
    {
        "Id": "e826c0940dc224f7b041ad2861229435f3ff7b0c5b9810f432eab78a1182eba7",
        "Created": "2018-06-07T11:20:34.05859919Z",
        "Path": "python",
        "Args": [
            "-u",
            "./firebase.py"
        ],
        "State": {
            "Status": "exited",
            "Running": false,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 0,
            "ExitCode": 137,
            "Error": "",
            "StartedAt": "2018-06-07T11:20:41.950594496Z",
            "FinishedAt": "2018-06-07T11:20:44.967301585Z"
        },
        "Image": "sha256:b88bb7323a0c74c54144521c0170b078df4282fe40bc124fd0cf1c5926d0584c",
        "ResolvConfPath": "/var/lib/docker/containers/e826c0940dc224f7b041ad2861229435f3ff7b0c5b9810f432eab78a1182eba7/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/e826c0940dc224f7b041ad2861229435f3ff7b0c5b9810f432eab78a1182eba7/hostname",
        "HostsPath": "/var/lib/docker/containers/e826c0940dc224f7b041ad2861229435f3ff7b0c5b9810f432eab78a1182eba7/hosts",
        "LogPath": "/var/lib/docker/containers/e826c0940dc224f7b041ad2861229435f3ff7b0c5b9810f432eab78a1182eba7/e826c0940dc224f7b041ad2861229435f3ff7b0c5b9810f432eab78a1182eba7-json.log",
        "Name": "/go-miner-container",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "shareable",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": true,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": [
                "label=disable"
            ],
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": null,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/f20d937621ab4301e8f85959ae660478473b0238976f5efa87dc8ee538ca5462-init/diff:/var/lib/docker/overlay2/938f7ab70c56b28e84d2444636d4bca2e8f41f82afb1423015f9bf768c788dd9/diff:/var/lib/docker/overlay2/db9771f2ad8ad54e0c07aab69bdd406e6a5f3e2a1abc3a5211a86fb2d509d970/diff:/var/lib/docker/overlay2/569fd809dceb91fc183a0022ae56495a3ef42d5ccf9cf520016aec7cb18918bd/diff:/var/lib/docker/overlay2/98d3eeec7feb2a4e8e6c8d392c73ae3119e0fa540b3782099d9530081960fa66/diff:/var/lib/docker/overlay2/d995e83a8c9b5a5255c82cc2ea99054d66a141af7a804d3894aebbcc96332f1f/diff:/var/lib/docker/overlay2/8e68793b217e1f5bd1788e3b94f17e15cdecc1b6464441d4d5dbee4058892ff0/diff:/var/lib/docker/overlay2/b100534660ed91a94e0e958241507487e13b89c2eb6745c8909979b4c31d8970/diff:/var/lib/docker/overlay2/ce783e4ff7bd08110d439e21791367779d55e39146f55295a658d908f4940975/diff:/var/lib/docker/overlay2/fc15200a4fe254c03f1598b03808f4072d3a4084a63f464b38001bea2ef89b35/diff:/var/lib/docker/overlay2/8a0500ec24f2b0ae05b55d40386f8d1566b32a1ee992a0e7482041648ab4ad30/diff:/var/lib/docker/overlay2/d2f9053d28f7a68e92e5fbb8a373b81d39b9d0168e104d7062d9b8bf3f4d5517/diff:/var/lib/docker/overlay2/8843a6d10e696375160435cc610e0b8ab91523739125bfb6dc8749188447f0be/diff:/var/lib/docker/overlay2/3680e27bc7f42b96e4ecb827fbefbf280c3b31412743723494c9608311889d14/diff:/var/lib/docker/overlay2/39b71a75d4c1aeef3e7fbc83b4778c030d04fefc4559cccab7a8b90f31f24049/diff:/var/lib/docker/overlay2/2cbe5685da3fa2b4c1b52e1eed93978ec4175bbc87ed77210700da08ddab4544/diff:/var/lib/docker/overlay2/bb29132edd2d7ca214d8edf8cb185319a2aa147052563b70a28f834dfb9c87da/diff:/var/lib/docker/overlay2/2f502551a2e74a16159820fd6aacd0c90d55bebc8c581fd1bbd46ab85b4201b5/diff:/var/lib/docker/overlay2/704c34d8f8978cee4485e65fa923f742666ebe8260872991fa8b08c56e7d3f9e/diff:/var/lib/docker/overlay2/214b24ce23b22631cf04b213fed09decc4b2fe08643ceedeecd98feb161d8ade/diff:/var/lib/docker/overlay2/2916cbe9887d1baf5f0d0345913dd6c7d7847a4e217520d261e36851f903ac91/diff:/var/lib/docker/overlay2/4af52cf964a3f100bc7ceec9e96f02b60305e8025556fce2a7e1bcbc399636db/diff:/var/lib/docker/overlay2/a15dba23f7c9f0ffb3c1de9497677862e8cd2adf7506f454b4d38671ca6b5815/diff:/var/lib/docker/overlay2/c6f4dffaf9c651828280cd80747659d2462db727aad47e04d68a25edfa5b9cd4/diff:/var/lib/docker/overlay2/db5507926c9564a2186bda441b3657ae2d7a6fc399df04eed7059be915e6554f/diff:/var/lib/docker/overlay2/9705a3a0d47e0cff848d4aa96f015438f6f30755fe5fc419e9cf6fef83af1c28/diff:/var/lib/docker/overlay2/25493cdc5e50330722910834a72ed517166129bc545eca5d0a2bd07a308ae6a8/diff:/var/lib/docker/overlay2/011396cec2412a73f8ae256fc084b7a3ef96e20f04d22ee06bc1e602005dca92/diff:/var/lib/docker/overlay2/7dbf65ddeff957b111e6b9223e178a597e1b3503236a38ab7dff80b96f0637d7/diff",
                "MergedDir": "/var/lib/docker/overlay2/f20d937621ab4301e8f85959ae660478473b0238976f5efa87dc8ee538ca5462/merged",
                "UpperDir": "/var/lib/docker/overlay2/f20d937621ab4301e8f85959ae660478473b0238976f5efa87dc8ee538ca5462/diff",
                "WorkDir": "/var/lib/docker/overlay2/f20d937621ab4301e8f85959ae660478473b0238976f5efa87dc8ee538ca5462/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "volume",
                "Name": "464aa3db13b65151bc7ca0f264efc415a005548d53a94160b54e4fa1cb55e1f8",
                "Source": "/var/lib/docker/volumes/464aa3db13b65151bc7ca0f264efc415a005548d53a94160b54e4fa1cb55e1f8/_data",
                "Destination": "/sys/fs/cgroup",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],
        "Config": {
            "Hostname": "250a29950ccb",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": true,
            "AttachStderr": true,
            "Tty": true,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "TINI_VERSION=0.14.0",
                "LC_ALL=C.UTF-8",
                "DEBIAN_FRONTEND=noninteractive",
                "UDEV=on",
                "QEMU_CPU=arm1176",
                "container=docker",
                "LANG=C.UTF-8",
                "PYTHON_VERSION=3.6.5",
                "PYTHON_PIP_VERSION=10.0.1",
                "SETUPTOOLS_VERSION=39.1.0",
                "PYTHON_DBUS_VERSION=1.2.4",
                "PYTHONPATH=/usr/lib/python3/dist-packages:",
                "INITSYSTEM=on"
            ],
            "Cmd": null,
            "ArgsEscaped": true,
            "Image": "beratuslu/gominer:latest",
            "Volumes": {
                "/sys/fs/cgroup": {}
            },
            "WorkingDir": "/easylinkraspberry",
            "Entrypoint": [
                "python",
                "-u",
                "./firebase.py"
            ],
            "OnBuild": null,
            "Labels": {
                "io.resin.architecture": "rpi",
                "io.resin.device-type": "raspberrypi",
                "io.resin.qemu.version": ""
            },
            "StopSignal": "37"
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "129cc44fd27bb811e19a0c0635b9d387392a9c29c084c9cceaa106e278d8b7e3",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/129cc44fd27b",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "546d9919184787d41e3f1359400ee76cf244f3f298ce406fec5988a6e2c5dae0",
                    "EndpointID": "",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "",
                    "DriverOpts": null
                }
            }
        }
    }
]

这里了望塔系统服务:

[Unit]
Description=Watchtower container
Requires=network-online.target docker.service
After=docker.service

[Service]
Restart=never
ExecStartPre=-/usr/bin/docker rm -f watchtower
ExecStart=/usr/bin/docker run --name watchtower --rm  -v /var/run/docker.sock:/var/run/docker.sock -e REPO_USER=USER_NAME -e REPO_PASS=PASSWORD v2tec/watchtower:armhf-latest -i 30 --cleanup --debug
ExecStop=/usr/bin/docker stop -t 2 watchtower

[Install]
WantedBy=default.target

这里是my-app systemd服务:

[Unit]
Description=My App
Requires=network-online.target docker.service
After=docker.service

[Service]
# Don't restart, conflicts with Watchtower
Restart=never
ExecStartPre=-/usr/bin/docker rm -f go-miner-container
ExecStart=/usr/bin/docker run --name go-miner-container --privileged -t beratuslu/gominer:latest
ExecStop=/usr/bin/docker stop -t 2 go-miner-container

[Install]
WantedBy=default.target

这是我的Docker文件:

FROM resin/raspberry-pi-python:3.6.5-slim
MAINTAINER Berat USLU "berat_uslu@hotmail.com"
# Enable systemd
ENV INITSYSTEM on

# Your code goes here

# Update aptitude with new repo
RUN apt-get update

# Install software
RUN apt-get install -y git

RUN apt-get install build-essential python-pip python-dev python-smbus python3-smbus

RUN git clone https://github.com/beratuslu/Pyrebase.git
WORKDIR /Pyrebase/
RUN python setup.py install
WORKDIR /

RUN git clone https://github.com/adafruit/Adafruit_Python_GPIO.git
WORKDIR /Adafruit_Python_GPIO/
RUN python setup.py install
WORKDIR /

RUN pip install dictdiffer
RUN pip install smbus2

#RUN apt-get -y install python3-rpi.gpio
RUN pip install RPi.GPIO

# Clone the conf files into the docker container
RUN git clone https://USER_NAME:PASSWORD@bitbucket.org/osasio/easylinkraspberry.git

WORKDIR /easylinkraspberry/
CMD [ "python", "-u", "./firebase.py" ] #asd4

1 个答案:

答案 0 :(得分:1)

Dockerfiledocker run ...命令中的某个位置,您需要提供CMDENTRYPOINT参数。您正在构建一个包含应用程序和依赖项的容器映像,但是没有定义实际的应用程序入口点,因此没有运行,这就是容器立即退出的原因。

有关文档,请参阅以下内容: