Docker容器在不同主机上的更改行为

时间:2017-07-05 09:10:50

标签: php docker dockerfile boot2docker docker-toolbox

我使用不同的工具(sentinelsat et sen2cor)构建了一个docker容器:

    #Modified Ubuntu docker image, adding some dependencies

    #Starting image
    FROM ubuntu

    #Install of Anaconda2-4.2.0 (from docker anaconda : https://github.com/ContinuumIO/docker-images/tree/master/anaconda)

    RUN apt-get update --fix-missing && apt-get install -y wget bzip2 ca-certificates \
        libglib2.0-0 libxext6 libsm6 libxrender1 \
        git mercurial subversion

    RUN echo 'export PATH=/opt/conda/bin:$PATH' > /etc/profile.d/conda.sh && \
        wget --quiet https://repo.continuum.io/archive/Anaconda2-4.2.0-Linux-x86_64.sh -O ~/anaconda.sh && \
        /bin/bash ~/anaconda.sh -b -p /opt/conda && \
        rm ~/anaconda.sh

    RUN apt-get install -y curl grep sed dpkg && \
        TINI_VERSION=`curl https://github.com/krallin/tini/releases/latest | grep -o "/v.*\"" | sed 's:^..\(.*\).$:\1:'` && \
        curl -L "https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini_${TINI_VERSION}.deb" > tini.deb && \
        dpkg -i tini.deb && \
        rm tini.deb && \
        apt-get clean

    ENV PATH /opt/conda/bin:$PATH

    RUN conda update conda -y

    RUN apt-get install -y zip

    #Sentinelsat  install (https://github.com/ibamacsr/sentinelsat)
    RUN pip install sentinelsat

    #Sen2cor install (from lvhengani : https://github.com/lvhengani/sen2cor_docker)
    ENV SEN2COR_VERSION='2.3.1'
    RUN wget http://step.esa.int/thirdparties/sen2cor/${SEN2COR_VERSION}/sen2cor-${SEN2COR_VERSION}.tar.gz && \
        tar -xvzf sen2cor-${SEN2COR_VERSION}.tar.gz && \
        cd sen2cor-${SEN2COR_VERSION} && \
        /bin/echo -e "y\ny\ny\n" | python setup.py install

    RUN rm sen2cor-${SEN2COR_VERSION}.tar.gz && rm -r /sen2cor-${SEN2COR_VERSION}

    #Path environment variables for sen2cor to allow use of sen2cor in command lines, useless with webpage
    ENV SEN2COR_HOME=/root/sen2cor
    ENV SEN2COR_BIN=/opt/conda/lib/python2.7/site-packages/sen2cor-${SEN2COR_VERSION}-py2.7.egg/sen2cor
    ENV GDAL_DATA=/opt/conda/lib/python2.7/site-packages/sen2cor-${SEN2COR_VERSION}-py2.7.egg/sen2cor/cfg/gdal_data

    #Install of Apache2 , PHP7 and MySQL
    RUN DEBIAN_FRONTEND=noninteractive && \
        apt-get update && \
        apt-get upgrade -y && \
        apt-get install -y --no-install-recommends iproute2 apache2 php7.0 libapache2-mod-php7.0 \
            php7.0-mysql php7.0-sqlite php7.0-bcmath php7.0-curl ca-certificates && \
        apt-get autoremove -y && \
        rm -rf /var/lib/apt/lists/* && \
        echo "ServerName $(ip route get 8.8.8.8 | awk '{print $NF; exit}')" >> /etc/apache2/apache2.conf && \
        a2enmod php7.0 && \
        a2enmod rewrite && \
        a2enmod env && \
        sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/7.0/apache2/php.ini

    RUN ln -sf /dev/stdout /var/log/apache2/access.log \
        && ln -sf /dev/stderr /var/log/apache2/error.log

    ENV APACHE_RUN_USER www-data
    ENV APACHE_RUN_GROUP www-data
    ENV APACHE_LOG_DIR /var/log/apache2
    ENV APACHE_LOCK_DIR /var/lock/apache2
    ENV APACHE_PID_FILE /var/run/apache2.pid

    #Allow PHP to use sen2cor, repositories where sen2cor has to write logs
    RUN chown www-data:www-data /opt/conda/lib/python2.7/site-packages/sen2cor-2.3.1-py2.7.egg/ && \
        chown www-data:www-data /root/  && \
        chown www-data:www-data /root/sen2cor/

    # Adding modified configuration files to allow Apache to access env variables from Sen2cor
    ADD ./conf_files/environment /etc/
    ADD ./conf_files/envvars /etc/apache2/

    #Move php files to apache repo
    COPY ./web_page  /var/www/html/
    RUN rm /var/www/html/index.html
    RUN chown www-data:www-data /var/www/html/ && \
        mkdir /var/www/html/downloads  && \
        chown www-data:www-data /var/www/html/downloads/

    #CMD /usr/sbin/apache2ctl -D FOREGROUND

我遇到的问题是,当使用具有此配置的docker工具箱在Windows上运行我的笔记本电脑时:

    $ docker version
    Client:
     Version:      17.05.0-ce
     API version:  1.29
     Go version:   go1.7.5
     Git commit:   89658be
     Built:        Fri May  5 15:36:11 2017
     OS/Arch:      windows/amd64

    Server:
     Version:      17.06.0-ce
     API version:  1.30 (minimum version 1.12)
     Go version:   go1.8.3
     Git commit:   02c1d87
     Built:        Fri Jun 23 21:51:55 2017
     OS/Arch:      linux/amd64
     Experimental: false

容器完美地执行PHP提出的操作。 我试图在具有此配置的虚拟机上运行此容器:

    DISTRIB_ID=Ubuntu
    DISTRIB_RELEASE=14.04
    DISTRIB_CODENAME=trusty
    DISTRIB_DESCRIPTION="Ubuntu 14.04 LTS"

和这个泊坞窗配置:

    Client:
     Version:      17.06.0-ce
     API version:  1.30
     Go version:   go1.8.3
     Git commit:   02c1d87
     Built:        Fri Jun 23 21:19:16 2017
     OS/Arch:      linux/amd64

    Server:
     Version:      17.06.0-ce
     API version:  1.30 (minimum version 1.12)
     Go version:   go1.8.3
     Git commit:   02c1d87
     Built:        Fri Jun 23 21:17:13 2017
     OS/Arch:      linux/amd64
     Experimental: false

当容器尝试访问repo / root / sen2cor /创建日志时,我有权限问题。 repo / root /和/ root / sen2cor都具有PHP可写的权限。

我尝试在两者上使用chmod 777,但它并没有解决问题。

我还在Windows,17.04和17.05上尝试过不同版本的Docker,并且容器在两者上都能完美运行。

我尝试在虚拟机上使用sudo docker run ..,我也尝试将用户添加到docker组,然后运行docker run ..并且我有相同的权限问题。

我甚至尝试在我的Windows设置上构建图像(测试它并且工作正常)然后将其上传到dockerhub并从虚拟机中将其拉出来运行它,但它仍然存在权限问题。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

找到解决方案,我只需将Sen2cor安装到另一个存储库。我不知道为什么,但默认情况下安装在/ root / sen2cor中的sen2cor,所以我不得不用/bin/echo -e "y\ny\ny\n" | python setup.py install替换“安装sen2cor”上的/bin/echo -e "y\nn\n/var/www/html/sen2cor\ny\ny\n" | python setup.py install命令,这样Apache可以访问它跑吧。

我仍然不知道为什么容器在主机上运行而不在另一个主机上运行,​​如果它来自Docker,这有点问题。