0
我正在爲Symfony開發的基礎Docker容器工作。我正在使用Docker Toolset for Windows。這裏是我的Dockerfile:碼頭集裝箱運行不正常
FROM centos:6.7
MAINTAINER Reynier Perez <[email protected]>
# 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 \[email protected]\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_007建議,我已經在官方Dockerfile添加httpd_foreground
作爲Apache和現在我看到的容器中運行,如果我跑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的,但我不知道
我可以就這兩個問題提供一些建議嗎?
你的意思是添加'RUN tailf/etc/http/logs/XXXXXX.log'? – ReynierPM
不作爲RUN,不。作爲CMD –
實際上,Apache官方鏡像使用'exec httpd -DFOREGROUND',這裏是CMD中使用的腳本https://github.com/docker-library/httpd/blob/bc72e42914f671e725d85a01ff037ce87c827f46/2.4/httpd-foreground –