运行后退出容器Docker

时间:2019-05-08 14:55:19

标签: docker sonarqube dockerfile

我有以下Dockerfile:

FROM sonarqube

ADD https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/4.0.0/sonar-gitlab-plugin-4.0.0.jar /opt/sonarqube/extensions/plugins/

USER root
RUN  chmod -R 655 /opt/sonarqube/extensions/plugins/ &&  chown -R sonarqube.sonarqube /opt/sonarqube/extensions/plugins/

当我运行图像构建时:

docker run -d -p 9000:9000 sonarqube-test

容器已创建并退出。

码头工人检查:

[
{
    "Id": "sha256:266ee2202a5d23c7deed92b67c70793d681ff3f46a9b8901586464a9785f0f03",
    "RepoTags": [
        "sonarqube-test:latest"
    ],
    "RepoDigests": [],
    "Parent": "sha256:19fe6021b3c114dc32bb70b276a2aa4c95d05eeba1d98920842290c5682378f4",
    "Comment": "",
    "Created": "2019-05-08T14:20:48.968804549Z",
    "Container": "752779a26450df746105d84c3172e56aef52cf7d7f12f10b594ae6987cc0b147",
    "ContainerConfig": {
        "Hostname": "d0b3d88572d1",
        "Domainname": "",
        "User": "root",
        "AttachStdin": false,
        "AttachStdout": false,
        "AttachStderr": false,
        "ExposedPorts": {
            "9000/tcp": {}
        },
        "Tty": false,
        "OpenStdin": false,
        "StdinOnce": false,
        "Env": [
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
            "LANG=C.UTF-8",
            "JAVA_HOME=/docker-java-home",
            "JAVA_VERSION=8u212",
            "JAVA_DEBIAN_VERSION=8u212-b01-1~deb9u1",
            "SONAR_VERSION=7.7",
            "SONARQUBE_HOME=/opt/sonarqube",
            "SONARQUBE_JDBC_USERNAME=sonar",
            "SONARQUBE_JDBC_PASSWORD=sonar",
            "SONARQUBE_JDBC_URL="
        ],
        "Cmd": [
            "/bin/sh",
            "-c",
            "chmod -R 655 /opt/sonarqube/extensions/plugins/ &&  chown -R sonarqube.sonarqube /opt/sonarqube/extensions/plugins/"
        ],
        "ArgsEscaped": true,
        "Image": "sha256:19fe6021b3c114dc32bb70b276a2aa4c95d05eeba1d98920842290c5682378f4",
        "Volumes": {
            "/opt/sonarqube/data": {}
        },
        "WorkingDir": "/opt/sonarqube",
        "Entrypoint": [
            "./bin/run.sh"
        ],
        "OnBuild": [],
        "Labels": {}
    },
    "DockerVersion": "17.05.0-ce",
    "Author": "",
    "Config": {
        "Hostname": "d0b3d88572d1",
        "Domainname": "",
        "User": "root",
        "AttachStdin": false,
        "AttachStdout": false,
        "AttachStderr": false,
        "ExposedPorts": {
            "9000/tcp": {}
        },
        "Tty": false,
        "OpenStdin": false,
        "StdinOnce": false,
        "Env": [
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
            "LANG=C.UTF-8",
            "JAVA_HOME=/docker-java-home",
            "JAVA_VERSION=8u212",
            "JAVA_DEBIAN_VERSION=8u212-b01-1~deb9u1",
            "SONAR_VERSION=7.7",
            "SONARQUBE_HOME=/opt/sonarqube",
            "SONARQUBE_JDBC_USERNAME=sonar",
            "SONARQUBE_JDBC_PASSWORD=sonar",
            "SONARQUBE_JDBC_URL="
        ],
        "Cmd": null,
        "ArgsEscaped": true,
        "Image": "sha256:19fe6021b3c114dc32bb70b276a2aa4c95d05eeba1d98920842290c5682378f4",
        "Volumes": {
            "/opt/sonarqube/data": {}
        },
        "WorkingDir": "/opt/sonarqube",
        "Entrypoint": [
            "./bin/run.sh"
        ],
        "OnBuild": [],
        "Labels": {}
    },
    "Architecture": "amd64",
    "Os": "linux",
    "Size": 976584087,
    "VirtualSize": 976584087,
    "GraphDriver": {
        "Data": {
            "RootDir": "/var/lib/docker/overlay/ad0d706f550d36e9ffd088d7e6ebf3454e8679a3587457cb0686719fbb20313b/root"
        },
        "Name": "overlay"
    },
    "RootFS": {
        "Type": "layers",
        "Layers": [
            "sha256:fbb641a8b94349e89886f65d79928e4673530e2a2b4d33c2c95e0426713f78e4",
            "sha256:604829a174eb966a2102e2e68c7669e1fe56721e8d7ea27f9a286aa33be8be20",
            "sha256:12cb127eee44270330891b1b610ce34e81f53a91a22e3a7f53f0632391d99892",
            "sha256:b17cc31e431beb2f39988dff23d04f85ba4b446fc0a13f304774852fa3c87d85",
            "sha256:af5ae48417766c4fa9b5ce9fc30a245c11dcb568c553bcf810c2fc137f62a97a",
            "sha256:e38df31d449cc619dbcab21468926927fdf4eff01498c8090cfddc0fb21e2a8a",
            "sha256:f350d0146bb3e9534f9bf10bfcdda4e413719644c78729f67667e16ffbd90325",
            "sha256:f7d12d4716672cbfdc98d3e431e63f8a5b236ab84ff80057dfadc6d1d0813fef",
            "sha256:3cc1c13e6e626d0073da455dc51b17a905ea5fc48a26e8d3e4d61a4218c105a9",
            "sha256:c6e01c4cf63e8d9b7d5f3de0a7a8d007bff05b3281dc559ebee890a9f79220a3",
            "sha256:e2c38440cb8a6f84bee3e3b2c45504812721cfa68d16fb601f8079873da8db35",
            "sha256:729909524637bf4631190a3112d993b0df9c1039d533f23452257bbe1eea883c",
            "sha256:f96562dd3433e564ae287d48ec2edf22f72cfdb60447e5df0d1caab63cfc2c27",
            "sha256:320c8f5ca5a033919c934ed8e82f8323e6fd0b38278a56a164c2718aa259b89c"
        ]
    }
}
]

泊坞窗记录此ID:

2019.05.08 14:22:59 INFO  app[][o.s.a.AppFileSystem] Cleaning or creating temp directory /opt/sonarqube/temp
2019.05.08 14:22:59 INFO  app[][o.s.a.es.EsSettings] Elasticsearch listening on /127.0.0.1:9001
2019.05.08 14:22:59 INFO  app[][o.s.a.p.ProcessLauncherImpl] Launch process[[key='es', ipcIndex=1, logFilenamePrefix=es]] from [/opt/sonarqube/elasticsearch]: /opt/sonarqube/elasticsearch/bin/elasticsearch
2019.05.08 14:22:59 INFO  app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
2019.05.08 14:22:59 INFO  app[][o.e.p.PluginsService] no modules loaded
2019.05.08 14:22:59 INFO  app[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2019.05.08 14:23:01 WARN  app[][o.s.a.p.AbstractProcessMonitor] Process exited with exit value [es]: 1
2019.05.08 14:23:01 INFO  app[][o.s.a.SchedulerImpl] Process [es] is stopped
2019.05.08 14:23:01 INFO  app[][o.s.a.SchedulerImpl] SonarQube is stopped

默认情况下,root用户是root用户,如果容器使用-it而不是-d,则通过传递/ bin / bash这样的容器来执行:docker run -it sonarqube-test /bin/bash

该插件已正确复制到目录中,并已为用户sonarqube进行了修改。

有人知道为什么要退出集装箱吗?

3 个答案:

答案 0 :(得分:0)

添加文件时您已经可以设置用户了:

FROM sonarqube

ADD --chown=sonarqube:sonarqube https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/4.0.0/sonar-gitlab-plugin-4.0.0.jar /opt/sonarqube/extensions/plugins/

我对此进行了测试,并且可以正常工作。

答案 1 :(得分:-1)

要解决此问题,请添加缺少的执行权限,如下所示:

FROM sonarqube

ADD https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/4.0.0/sonar-gitlab-plugin-4.0.0.jar /opt/sonarqube/extensions/plugins/

USER root
RUN  chmod -R 555 /opt/sonarqube/extensions/plugins/ &&  chown -R sonarqube.sonarqube /opt/sonarqube/extensions/plugins/

答案 2 :(得分:-2)

如果您有ENTRYPOINT,则在docker-run结束时您的/bin/bash不能与-d一起使用(-it可以正常工作)。

您需要在exec tail -f /dev/null的末尾添加while true; do sleep 1000; doneENTRYPOINT

exec tail -f /dev/null是最有效的,您可以在此处查看:A flag in docker to always be up

这是具有以下解决方案的码头工人: https://github.com/sequenceiq/hadoop-docker/blob/master/bootstrap.sh

这是一个oficial fedora solution,他们在末尾创建一个CMD ["/bin/bash"]https://github.com/fedora-cloud/docker-brew-fedora/blob/4dbc2ccd3b4d52258981eaf12043025054d53023/x86_64//Dockerfile