我正在使用基础Docker容器进行Symfony开发。我正在使用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
使用以下方法构建机器时
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
我没有看到任何容器在运行,为什么?我在这里错过了什么?
更新
关注@ cricket_007建议我在Apache的官方Dockerfile中添加了httpd_foreground
,现在我看到容器正在运行,如果我运行docker ps
但我仍然遇到一些问题:
docker run -it --name=symfony symfony-dev bash
进入bash,我收到此错误:new state of nil is invalid
我不知道如何修复。http://172.17.0.2/info.php
我对firewalld和/或SELinux有一些怀疑,但我不确定我可以就这两个问题提出一些建议吗?
答案 0 :(得分:1)
您的容器在启动后即将死亡,因为您的命令service httpd restart
不会保持打开任何前台进程。
您可以tail -f
Apache日志文件,例如作为CMD并使用RUN重新启动服务器,就像您目前一样。