Recommand · October 22, 2021 0

Can't access docker container via host browser. Ping is allowed

I created first time some containers via docker-compose in the same new network. After while the env is completed. I see running containers via docker ps. Normally after that i can use containers. But when I tried to access wordpress web page from host via localhost:20000 or :20000. I get ERR_Connection refused. I was expecting info about "Error connecnting to the database".I can ping the containers by docker containers ip from the host. So maybe someone know how to fix that and get access to them.

This happens with this new network – network_1. Other containers like pihole + portainer in default bridge network are accessible from whole host network.
Thank You.

version: '3'

services:
  # Database
  db:
    image: linuxserver/mariadb
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    ports:
      - 3306:3306
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: wordpress
      MYSQL_USER: user
      MYSQL_PASSWORD: password
    networks:
      - network_1
  # phpmyadmin
  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - 3308:80
    environment:
      PMA_HOST: 1
      MYSQL_ROOT_PASSWORD: password
    networks:
      - network_1
  # WordPress
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - 20000:80
    restart: always
    volumes: ['./:/var/www/html']
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: user
      WORDPRESS_DB_PASSWORD: password
    networks:
      - network_1
  # Nextcloud    
  nextcloud:
    image: nextcloud
    restart: always
    ports:
      - 30000:80
    depends_on:
      - db
    volumes:
      - nextcloud:/var/www/html
    environment:
      MYSQL_PASSWORD: password
      MYSQL_DATABASE: nextcloud
      MYSQL_USER: user
      MYSQL_HOST: db:3306
    networks:
      - network_1      
networks:
  network_1:
volumes:
  db_data:
  nextcloud:

Some commands from docker:

    pi@raspberrypi:~ $ docker ps
CONTAINER ID   IMAGE                           COMMAND                  CREATED       STATUS                   PORTS
                              NAMES
52d11a5c2931   wordpress:latest                "docker-entrypoint.s…"   2 hours ago   Up 2 hours               0.0.0.0:20000->80/tcp, :::20000->80/tcp
                              dom_wordpress_1
39feec5309d3   phpmyadmin/phpmyadmin           "/docker-entrypoint.…"   2 hours ago   Up 2 minutes             0.0.0.0:3308->80/tcp, :::3308->80/tcp
                              dom_phpmyadmin_1
62a943db01f2   nextcloud                       "/entrypoint.sh apac…"   2 hours ago   Up 2 hours               0.0.0.0:30000->80/tcp, :::30000->80/tcp
                              dom_nextcloud_1
0681159165df   linuxserver/mariadb             "/init"                  2 hours ago   Up 2 hours               3306/tcp
                              dom_db_1
d0b6ece5c5aa   portainer/portainer-ce:latest   "/portainer"             4 hours ago   Up 4 hours               0.0.0.0:9000->9000/tcp, :::9000->9000/tcp, 8000/tcp, 0.0.0.0:9443->9443/tcp, :::9443->9443/tcp
                              portainer
71ee89deb6de   nginx:latest                    "/docker-entrypoint.…"   12 days ago   Up 4 hours               0.0.0.0:80->80/tcp, :::80->80/tcp
                              nginx
03fcbea93e14   pihole/pihole:latest            "/s6-init"               5 weeks ago   Up 4 hours (unhealthy)   0.0.0.0:53->53/tcp, 0.0.0.0:53->53/udp, :::53->53/tcp, :::53->53/udp, 67/udp, 0.0.0.0:5000->80/tcp, :::5000->80/tcp, 0.0.0.0:5001->443/tcp, :::5001->443/tcp   pihole

And docker inspect. !-No output for dom_db_1 and dom_phpmyadmin_1, and running pihole

pi@raspberrypi:~/docker-compose-Templates/dom $ docker port dom_db_1
pi@raspberrypi:~/docker-compose-Templates/dom $ docker port pihole
443/tcp -> 0.0.0.0:5001
443/tcp -> :::5001
53/tcp -> 0.0.0.0:53
53/tcp -> :::53
53/udp -> 0.0.0.0:53
53/udp -> :::53
80/tcp -> 0.0.0.0:5000
80/tcp -> :::5000

I think

  # Database
  db:
    image: linuxserver/mariadb
    volumes:
      - db_data:/var/lib/mysql
    restart: always
        ports:
      - 3306:3306

should be

  # Database
  db:
    image: linuxserver/mariadb
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    ports:
      - 3306:3306