0

I am trying to set my PHP application with Docker. It builds successfully but when I hit in browser - its showing 0.0.0.0 didn’t send any data.

Here is my docker-compose.yml ::

version: '2'
services:

# The Application
app:
  build:
    context: ./
    dockerfile: app.dockerfile
working_dir: /Users/sr/Sites/zogo-commerce/public
volumes:
  - ./:/var/www/zogo-commerce/public
environment:
  - "DB_PORT=3306"
  - "DB_HOST=127.0.0.1"

# The Web Server
web:
  build:
    context: ./
    dockerfile: web.dockerfile
working_dir: /Users/sr/Sites/zogo-commerce/public
volumes_from:
  - app
ports:
  - 9090:80

# The Database
database:
  image: mysql:5.6
  volumes:
    - dbdata:/usr/local/bin/mysql
environment:
  - "MYSQL_DATABASE=zogo_commerce"
  - "MYSQL_USER=root"
  - "MYSQL_PASSWORD=root1234"
  - "MYSQL_ROOT_PASSWORD=root1234"
ports:
    - "33061:3306"
volumes:
 dbdata:

File web.dockerfile ::

FROM nginx:1.10

ADD vhost.conf /etc/nginx/conf.d/default.conf

File app.dockerfile ::

FROM php:7.0.4-fpm

RUN apt-get update && apt-get install -y libmcrypt-dev \
mysql-client libmagickwand-dev --no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& docker-php-ext-install mcrypt pdo_mysql

Virtual host file vhost.conf ::

server {
listen       8080;
server_name  zogo-commerce.local;

root /var/www/zogo-commerce/public;

index index.php index.html index.htm;

try_files $uri $uri/ /index.php?$args;

location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
    fastcgi_read_timeout 600;
}

}

Here is my containers :

CONTAINER ID        IMAGE               COMMAND                  
CREATED             STATUS                           PORTS                           
NAMES
11d6a74becfe        zogo-commerce_web   "nginx -g 'daemon of…"   5 
minutes ago       Up 5 minutes                     443/tcp, 
0.0.0.0:9090->80/tcp   zogo-commerce_web_1
032249f95de8        zogo-commerce_app   "php-fpm"                5 
minutes ago       Up 6 minutes                     9000/tcp                        
zogo-commerce_app_1
9515f4708708        mysql:5.6           "docker-entrypoint.s…"   18 
minutes ago      Up 6 minutes                     0.0.0.0:33061- 
>3306/tcp         zogo-commerce_database_1

It seems build is okay but in brwser http://0.0.0.0:9090/ showing ERROR.

How do I resolve this issue to make it workable ? thanks in advance::

Here is my Files:

docker-compose.yml: https://pastebin.com/bZUHMRvr
app.dockerfile: https://pastebin.com/bUKZ2suj
web.dockerfile: https://pastebin.com/0qbCGnWm
vhost.conf: https://pastebin.com/MnZkbTe2
docker-compose up :: Error -> https://pastebin.com/6HEgpJk1
Selim Reza
  • 625
  • 8
  • 21
  • 1
    `0.0.0.0` is not a valid IP address for an endpoint. It means *any* IP. You should use `localhost`. – Jonathon Reinhart May 03 '18 at 14:01
  • @JonathonReinhart :: same for http://localhost:9090/ and http://127.0.0.1:9090/ . === both are showing same error – Selim Reza May 03 '18 at 14:05
  • You should try opening a shell in the container itself, and try to cURL the url from within the container, to make sure it's running on the port you think it is, etc. – ygesher May 03 '18 at 14:16
  • @ygesher : I didn't get your point . would you please elaborate little more ? – Selim Reza May 03 '18 at 14:23
  • @SelimReza At this point, all you know is that what you expected to happen isn't happening. The first question you need to answer is "which link in this chain is broken?". My suggestion was to start near the beginning, by checking that the web server is alive and well, and listening on the proper port. – ygesher May 03 '18 at 14:28
  • @ygesher .. sure .. going to start from beginning – Selim Reza May 03 '18 at 14:32
  • Here is my Files: docker-compose.yml: https://pastebin.com/bZUHMRvr app.dockerfile: https://pastebin.com/bUKZ2suj web.dockerfile: https://pastebin.com/0qbCGnWm vhost.conf: https://pastebin.com/MnZkbTe2 docker-compose up :: Error -> https://pastebin.com/6HEgpJk1 – Selim Reza May 04 '18 at 13:31

2 Answers2

1

This 0.0.0.0 is not a valid IP address, but a non-routable meta-address Your application is reachable on your machines IP address / hostname on port 9090.

If you are unsure, what your hostname is, you can run in linux;

hostname
namokarm
  • 636
  • 1
  • 6
  • 19
  • I am using this one in Mac OSX ... in vhost file I added `server_name zogo-commerce.local;` and added in hosts file .. and same error for `http://zogo-commerce.local:9090/` – Selim Reza May 03 '18 at 14:11
  • Can you take a look at https://stackoverflow.com/questions/4421633/who-is-listening-on-a-given-tcp-port-on-mac-os-x the accepted answer and check who is listening on port 9090? Also do you get the same error message? – namokarm May 03 '18 at 14:16
  • ` lsof -nP -i4TCP:9090 | grep LISTEN com.docke 1021 sr 20u IPv4 0xb39ab05230500911 0t0 TCP *:9090 (LISTEN)` – Selim Reza May 03 '18 at 14:22
  • @SelimReza I'm not familiar with Mac OS, that's why i added the link, but if i'm guessing, could it be, your machine is named "com.docke"? Check the output without using grep - "lsof -nP -i4TCP:9090" and that should list all ports. ygeshar was trying to say that you should use docker exec -it container_id bash command, to open an interactive shell of you web server and inside the container run curl or wget localhost on port 80. From your comments, the container if would be 11d6a74becfe, so you could run docker exec -it 11d6a74becfe bash and then curl localhost:80 – namokarm May 03 '18 at 15:50
  • Here is my Files: docker-compose.yml: https://pastebin.com/bZUHMRvr app.dockerfile: https://pastebin.com/bUKZ2suj web.dockerfile: https://pastebin.com/0qbCGnWm vhost.conf: https://pastebin.com/MnZkbTe2 docker-compose up :: Error -> https://pastebin.com/6HEgpJk1 – Selim Reza May 04 '18 at 13:31
0

Its not only docker issue. look at vhost.conf, where you open 8080, that's means httpd server listen 8080 port but in docker-compose.yml you map host port 9090 with container port 80. where you should open 8080 rather than 80.

There was another problem on Dockerfile. You didn't expose any port. you should expose 8080

hope everything will be ok

  • Here is my Files: docker-compose.yml: https://pastebin.com/bZUHMRvr app.dockerfile: https://pastebin.com/bUKZ2suj web.dockerfile: https://pastebin.com/0qbCGnWm vhost.conf: https://pastebin.com/MnZkbTe2 docker-compose up :: Error -> https://pastebin.com/6HEgpJk1 – Selim Reza May 04 '18 at 13:31
  • It's not necessary to expose a port is you explicitly publish it. The `EXPOSE` declaration in a Dockerfile only sets metadata on the image. This metadata is a form of documentation to the person running the image, useful for the `-P` option, and used by a few other tools like self configuring reverse proxies. – BMitch May 04 '18 at 14:43
  • Selim Reza - is you issues resolved. If not then knock me at skype uzzal2k5 – Md Shafiqul Islam May 12 '18 at 17:05