Docker容器运行不正常

我在Symfony开发的基础Docker容器中工作。 我正在使用Docker Toolset for Windows。 这是我的Dockerfile:

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 

当我使用以下方式构build机器时:

 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 

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

UPDATE

在@ cricket_007build议之后,我添加了Apache官方Dockerfile中的httpd_foreground,现在我看到容器正在运行,如果我运行docker ps但是我仍然遇到一些问题:

  • 如果我运行容器进入bash作为docker run -it --name=symfony symfony-dev bash我得到这个错误: new state of nil is invalid ,我不知道如何解决。
  • 另一方面,我看到172.17.0.2作为IP地址,但我不能达到它的Apache意义http://172.17.0.2/info.php我有一些关于firewalld和/或SELinux可疑,但我不是当然

我可以就这两个问题提出一些build议吗?

您的容器在启动后即将死亡,因为您的命令service httpd restart不会保持打开任何前台进程。

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