2

I'm learning docker for my first project using Slim framework (PHP). I created a dockerfile to build an image with all the source code in it. When I run the image with the run command it shows me

<b>Warning</b>:  Unknown: php_network_getaddresses: getaddrinfo failed: Name does not resolve in <b>Unknown</b> on line <b>0</b><br />
[Sat Jun 15 09:41:14 2019] Failed to listen on  127.0.0.1:8080 (reason: php_network_getaddresses: getaddrinfo failed: Name does not resolve)

Dockerfile looks like:

FROM php:7-alpine
COPY . /var/www
WORKDIR /var/www
CMD [ "php", "-S 127.0.0.1:8080 -t public" ]

Docker run command is:

sudo docker run -it --rm --network="host" --expose 8080 --name cm2 collection_manager_1

Don't know how I can fix this. Can someone help me?

2
  • Do you really want to listen on localhost? I think it should be -S 0.0.0.0:8080 Commented Jun 15, 2019 at 10:50
  • When I try with -S 0.0.0.0:8080 I'm getting the same error (but failt to listen on 0.0.0.0:8080 Commented Jun 15, 2019 at 11:52

1 Answer 1

6

The CMD syntax seems to have some problem. All the arguments in the command should be comma separated and inside the double quotes.

I made a slight change in Dockerfile and it worked.

FROM php:7-alpine
COPY . /var/www
WORKDIR /var/www
CMD [ "php", "-S", "0.0.0.0:8080", "-t", "html" ]

docker build -t testimage:v1 .

[mchawre@jumphost try]$ docker run -it --rm --network="host" --expose 8080 --name testrun testimage:v1
PHP 7.3.6 Development Server started at Sat Jun 15 11:50:19 2019
Listening on http://0.0.0.0:8080
Document root is /var/www/html
Press Ctrl-C to quit.

NOTE: Change 127.0.0.1 to 0.0.0.0 so that you can hit the php using public/private ip of your machine rather than just localhost.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.