Docker 容器未 运行 正确

Docker container not running properly

我在一个用于 Symfony 开发的基础 Docker 容器中工作。我正在为 Windows 使用 Docker 工具集。这是我的 Docker 文件:

FROM        centos:6.7
MAINTAINER  Reynier Perez <reynierpm@gmail.com>

# basic env fix
ENV             TERM xterm

# Install REMI and EPEL repos
RUN     yum update -y
RUN     yum install -y mc wget yum-utils htop nano curl git
RUN     wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm \
        && wget http://rpms.remirepo.net/enterprise/remi-release-6.rpm \
        && rpm -Uvh remi-release-6.rpm epel-release-latest-6.noarch.rpm

RUN     yum-config-manager --enable remi-php70
RUN     yum install -y  php \
                        php-common \
                        php-cli \
                        php-gd \
                        php-intl \
                        php-mbstring \
                        php-mcrypt \
                        php-opcache \
                        php-pdo \
                        php-pear \
                        php-pecl-apcu \
                        php-imagick \
                        php-pecl-xdebug \
                        php-xml \
                        php-mysqlnd \
                        php-soap \
                        php-pdo-dblib

RUN         curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer
RUN         curl -LsS http://symfony.com/installer -o /usr/local/bin/symfony && chmod a+x /usr/local/bin/symfony

# Configure Services
# Create a copy of default files and remove them
# Apache
RUN         cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.default
RUN         rm -f /etc/httpd/conf/httpd.conf
ADD         httpd.conf /etc/httpd/conf/
# Add default VirtualHost
ADD         vhost.conf /etc/httpd/conf.d/
#PHP
RUN         cp /etc/php.ini /etc/php.ini.default
RUN         rm -f /etc/php.ini
ADD         php.ini /etc/
# Add PHP info default script
ADD         info.php /var/www/html
# Setup permissions
RUN         chown -R apache:root /var/www/html && \
            find /var/www/html -type d -print0 | xargs -0 chmod 2775 && \
            find /var/www/html -type f -print0 | xargs -0 chmod 0664

# Mount Volumes
VOLUME      /var/www/html
WORKDIR     /var/www/html

EXPOSE      80

CMD         service httpd restart

当我构建机器时使用:

docker build --tag=symfony-dev .

我收到这条消息:

Successfully built c7bc46e1f84c 
SECURITY WARNING: You are building a
Docker image from Windows against a non-Windows Docker host. All files
and directories added to build context will have '-rwxr-xr-x'
permissions. It is recommended to double check and reset permissions
for sensitive files and directories.

下一步是 运行 容器使用:

docker run symfony-dev

然后我尝试查看该容器的信息:

docker inspect symfony-dev

我得到了一个 JSON 这样的:

[
    {
        "Id": "sha256:c7bc46e1f84c6d1a543c515d134184486dcb0e3e81c81f269ff1bb10791a3c9e",
        "RepoTags": [
            "symfony-dev:latest"
        ],
        "RepoDigests": [],
        "Parent": "sha256:db8021c4307e547ae7fee4afd3b964e72fde6422dbb8a5292b4bf441beb7d0b4",
        "Comment": "",
        "Created": "2016-04-02T02:16:45.891399606Z",
        "Container": "e02be1ee3e12ef79bff0c0bbb7b7751f7368d5c06872df37a58439d21d69d57f",
        "ContainerConfig": {
            "Hostname": "72ba20be3774",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "TERM=xterm"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) CMD [\"/bin/sh\" \"-c\" \"service httpd restart\"]"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:db8021c4307e547ae7fee4afd3b964e72fde6422dbb8a5292b4bf441beb7d0b4",
            "Volumes": {
                "/var/www/html": {}
            },
            "WorkingDir": "/var/www/html",
            "Entrypoint": null,
            "OnBuild": [],
            "Labels": {
                "License": "GPLv2",
                "Vendor": "CentOS"
            }
        },
        "DockerVersion": "1.10.3",
        "Author": "Reynier Perez \u003creynierpm@gmail.com\u003e",
        "Config": {
            "Hostname": "72ba20be3774",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "TERM=xterm"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "service httpd restart"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:db8021c4307e547ae7fee4afd3b964e72fde6422dbb8a5292b4bf441beb7d0b4",
            "Volumes": {
                "/var/www/html": {}
            },
            "WorkingDir": "/var/www/html",
            "Entrypoint": null,
            "OnBuild": [],
            "Labels": {
                "License": "GPLv2",
                "Vendor": "CentOS"
            }
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 756378663,
        "VirtualSize": 756378663,
        "GraphDriver": {
            "Name": "aufs",
            "Data": null
        }
    }
]

但是IP地址在哪里?我如何到达该容器上的 Apache?如果我 运行 命令 ps 如下:

docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

我没有看到任何容器 运行ning,为什么?我在这里遗漏了什么?

更新

按照@cricket_007的建议,我添加了httpd_foreground作为Apache的官方Docker文件,现在我看到容器运行ning如果我运行 docker ps 但我仍然有一些问题:

我可以就这两个问题提点建议吗?

您的容器在启动后快要死了,因为您的命令 service httpd restart 没有保持打开任何前台进程。

您可以 tail -f Apache 日志文件,例如作为 CMD,并使用 运行 像您现在一样重新启动服务器。