Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker + webdevops: "This site can’t be reached"

On a current project I use Docker. I must clarify that I am pretty inexperienced at it.

My project is a PHP/Symfony project. Until then, I used nginx:alpine and phpdocker/php-fpm to have my project running on my dev environment. However, I found these unfit to my case as my production actually uses Apache.

I found another project I'm on uses the webdevops Docker images without trouble. I want to replace the two containers listed above with a single one, the webdevops/php-apache-dev:alpine docker image.

Although the configuration between the two projects seems almost identical, my dev environment does not seem to work properly: I end up with this:

This site can’t be reached - 172.18.0.7 refused to connect.

(I also use Traefik, but the routed URI does not work any better. The error message is slightly different though: Bad Gateway).

I find myself unable to debug this. I don't even know where to look.

Below is the docker-compose.yml configuration I want to use:

version: '3.2'

services:
  app:
    image: webdevops/php-apache-dev:alpine
    container_name: my-app
    working_dir: /app
    env_file: .env
    environment:
      WEB_DOCUMENT_ROOT: /public
      WEB_DOCUMENT_INDEX: index.php

      LOG_STDOUT: ./var/log/app.stdout.log
      LOG_STDERR: ./var/log/app.stderr.log

      # @todo list of unwanted PHP modules, cf. https://dockerfile.readthedocs.io/en/latest/content/DockerImages/dockerfiles/php-apache-dev.html#php-modules
      # PHP_DISMOD:

      php.error_reporting: E_ALL
      PHP_DISPLAY_ERRORS: 1

      PHP_POST_MAX_SIZE: 80M
      PHP_UPLOAD_MAX_FILESIZE: 200M
      PHP_MEMORY_LIMIT: 521M
      PHP_MAX_EXECUTION_TIME: 300

      PHP_DATE_TIMEZONE: Europe/Paris
    volumes:
        - .:/app
        # - ./docker/apache2/conf.d:/opt/docker/etc/httpd/conf.d
        - ~/.ssh:/home/application/.ssh:ro
        - ~/.composer:/home/application/.composer
    depends_on:
      - elasticsearch
      - database

The other containers work just as well as they did before. This one is the only one that fails.

When calling docker-compose up no error is thrown. All the logs I could find within the container remain silent. As far I as can tell, Traefik does not seem to be the problem. Here is the result of docker ps:

[/var/www/html/citizen-game]$ docker ps                                                                                              *[master] 
CONTAINER ID        IMAGE                                                 COMMAND                  CREATED             STATUS                 PORTS                                                                                        NAMES
6e9639e7a84d        webdevops/php-apache-dev:alpine                       "/entrypoint supervi…"   4 hours ago         Up 4 hours             80/tcp, 443/tcp, 9000/tcp                                                                    my-app-app
be1b90fdf768        docker.elastic.co/elasticsearch/elasticsearch:6.2.4   "/usr/local/bin/dock…"   4 hours ago         Up 4 hours (healthy)   9200/tcp, 9300/tcp                                                                           my-app-elasticsearch
76fb8743a12f        phpmyadmin/phpmyadmin                                 "/run.sh supervisord…"   4 hours ago         Up 4 hours             80/tcp, 9000/tcp                                                                             my-app-phpmyadmin
dd41b4afe267        mysql:5.7                                             "docker-entrypoint.s…"   4 hours ago         Up 4 hours (healthy)   3306/tcp, 33060/tcp                                                                          my-app-database
91893783bcb1        rabbitmq:3.7-management                               "docker-entrypoint.s…"   4 hours ago         Up 4 hours             4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp   my-app-rabbitmq
63f551884bbf        traefik:maroilles                                     "/traefik --web --do…"   4 hours ago         Up 4 hours             0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:8080->8080/tcp 

My question is, I guess: how can I debug this? Am I missing something trivial?

Edit

Here is (part of) the content of the docker-compose.override.yml file:

version: '3.2'

services:
    app:
      volumes:
        - ~/.ssh:/home/application/.ssh
        - ~/.composer:/home/application/.composer
      labels:
        - "traefik.backend=my-app"
        - "traefik.frontend.rule=Host:my-app.docker"
        - "traefik.docker.network=proxy"
      networks:
        - internal
        - proxy
      environment:
        PHP_DEBUGGER: xdebug
        #XDEBUG_REMOTE_HOST: <your host IP address>
        XDEBUG_REMOTE_PORT: 9000
        XDEBUG_REMOTE_AUTOSTART: 1
        XDEBUG_REMOTE_CONNECT_BACK: 1
        XDEBUG_PROFILER_ENABLE: 1
        XDEBUG_PROFILER_ENABLE_TRIGGER: 1000

    traefik:
      image: traefik
      container_name: citizen-game-traefik
      command: --web --docker --docker.domain=docker --logLevel=DEBUG
      ports:
        - "80:80"
        - "443:443"
        - "8080:8080"
      volumes:
        - /var/run/docker.sock:/var/run/docker.sock
      restart: always
      networks:
        - internal
        - proxy

    rabbitmq:
      networks:
        - internal
        - proxy

networks:
    proxy:
      external:
        name: traefik
    internal:

EDIT 2:

@Mostafa

I ran the following:

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' my-app-app

Result is:

172.18.0.7172.19.0.5

Trying these directly from the browser fails "This site can't be reached". I suppose it was to be expected.

I ran the following from inside the container:

bash-4.4# supervisorctl status apache:apached
apache:apached                   RUNNING   pid 13575, uptime 0:00:00

As suggested, I used ss -plant | grep 80. This does not work from within the container. Here is the result when called outside of it:

[/var/www/html/my-app]$ ss -plant | grep 80                                                                 
LISTEN      0        80              127.0.0.1:3306              0.0.0.0:*                                                                                      
ESTAB       0        0            192.168.1.88:39360      198.252.206.25:443     users:(("chromium-browse",pid=4203,fd=80))                                     
SYN-SENT    0        1            192.168.1.88:50680     192.241.181.178:443     users:(("chromium-browse",pid=4203,fd=41))                                     
LISTEN      0        128                     *:80                      *:*                                                                                      
LISTEN      0        128                     *:8080                    *:*

I'm not sure it tells much though. I tried to install ss from inside the container with apk but:

bash-4.4# apk add ss
ERROR: unsatisfiable constraints:
  ss (missing):
    required by: world[ss]

EDIT 3:

Here is the result of calling netstat:

bash-4.4# netstat -plant
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      229/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.11:32843        0.0.0.0:*               LISTEN      -
tcp        0      0 :::22                   :::*                    LISTEN      229/sshd
tcp        0      0 :::9000                 :::*                    LISTEN      225/php-fpm.conf)

bash-4.4# netstat -plant | grep httpd
(nothing)

I'm not sure how much this helps though, since my other project, that works, yields the same result n bash-4.4# netstat -plant | grep httpd. Without the grep, it includes much more lines, though.

like image 304
Zephyr Avatar asked Oct 25 '19 13:10

Zephyr


People also ask

Can I run Jupyter notebook from a Docker container?

Once the Docker image is built successfully, you can the following command to starts a container running a Jupyter Notebook server with all Python libraries that are defined in a requirements. txt file and jupyter/scipy-notebook in your machine.

Does a Docker container have an IP address?

By default, the container is assigned an IP address for every Docker network it connects to. The IP address is assigned from the pool assigned to the network, so the Docker daemon effectively acts as a DHCP server for each container. Each network also has a default subnet mask and gateway.


1 Answers

As the output that you have posted described the exposed ports 80,443,9000 for the container from this image webdevops/php-apache-dev:alpine

Then you can access the container using its IP directly from the browser. So first you need to ensure from the following:

  • Check if 172.18.0.7 is the actual IP of my-app-app container, use the following command to check the IP of your running container
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' my-app-app

Or just docker inspect my-app-app to get all info about the container

  • Check the logs for my-app-app and you may need to enter the container itself and check if apache is actually running by executing the following supervisorctl command which will tell you about the status of apache service
$ supervisorctl status apache:apached
apache:apached                   RUNNING   pid 72, uptime 0:07:43

If apache is running correctly then you should be able to browse the content using the container IP, in my case it gives me something like this as I don't have an actual application

enter image description here

Regarding your issue with traefik which is Bad Gateway that's because traefik itself cannot reach your backend service which is the my-app-app container in our case. you need to ensure that both traefik and my-app-app are within the same network or at least they can ping each other's IPs

Update:

Instead of ss it turns out the image contains netstat command, in order to check what port is used by apache you can do the following from inside the container:

# netstat -plant | grep httpd
tcp        0      0 :::80                   :::*                    LISTEN      98/httpd
tcp        0      0 :::443                  :::*                    LISTEN      98/httpd
like image 60
Mostafa Hussein Avatar answered Oct 27 '22 15:10

Mostafa Hussein