duanjue7745 2018-03-26 20:41
浏览 440
已采纳

DOCKER:ERR_EMPTY_RESPONSE - Mac

I'm new to Docker and just made my first steps. I wanted to play a little bit with docker and was about configuring a Dockerfile for yii:

FROM php:7.2.3-apache

RUN curl -sS https://getcomposer.org/installer | php && \
    mv composer.phar /usr/local/bin/composer

RUN apt-get update && apt-get install -y git unzip zip

EXPOSE 8080

RUN composer create-project --prefer-dist yiisoft/yii2-app-basic test

Then I run the container with:

docker container run -d --name test -p 8080:8080 test-yii

When I go to localhost:8080 i got an ERR_EMPTY_RESPONSE. This is the network result of docker container inspect:

"Ports": {
     "80/tcp": null,
     "8080/tcp": [
          {
               "HostIp": "0.0.0.0",
               "HostPort": "8080"
          }
     ]
},

I appreciate every hint that helps me to solve this issue!

Edit: I forgot to mention that i connect to the container and then run php yii serve to test if Yii runs and this results in the above described problem.

  • 写回答

1条回答 默认 最新

  • dongtai419309 2018-03-28 12:20
    关注

    YII is not started when you create a container. That's because it isn't defined in Dockerfile. Only apache starts there, because that's come from the image php:7.2.3-apache.

    The correct Dockerfile is:

    FROM php:7.2.3-apache
    
    RUN curl -sS https://getcomposer.org/installer | php && \
        mv composer.phar /usr/local/bin/composer
    
    RUN apt-get update && apt-get install -y git unzip zip
    
    EXPOSE 8080
    
    RUN composer create-project --prefer-dist yiisoft/yii2-app-basic test
    CMD test/yii serve 0.0.0.0 
    

    Now, CMD layer with yii overlaps CMD layer from php:7.2.3-apache image.

    If you want to start both yii and apache inside a container you should look to these pieces of advice.

    Update to the Edit section in the question:

    You need to run php yii serve 0.0.0.0. Otherwise yii binds to localhost:8080 and is only accessible inside a container

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!