1

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.

codelifter
  • 218
  • 5
  • 14
  • Follow official doc https://github.com/yiisoft/yii2-docker, or even my version that contains mysql and phpmyadmin support: https://github.com/FabrizioCaldarelli/yii2-docker – Fabrizio Caldarelli Mar 26 '18 at 20:54
  • Can you run `curl localhost:8080 -v` and paste the output here? – Yuankun Mar 27 '18 at 03:34
  • @Yuankun this is the result: `Rebuilt URL to: localhost:8080/ * Trying ::1... * TCP_NODELAY set * Connected to localhost (::1) port 8080 (#0) > GET / HTTP/1.1 > Host: localhost:8080 > User-Agent: curl/7.54.0 > Accept: */* > * Empty reply from server * Connection #0 to host localhost left intact curl: (52) Empty reply from server` – codelifter Mar 27 '18 at 17:43

1 Answers1

3

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

nickgryg
  • 25,567
  • 5
  • 77
  • 79