简体   繁体   中英

Docker can't connect to adminer port

Hi i'm working with docker-compose file to work with postgresql and adminer(database interface).

I followed the instruction on the postgres image on docker hub and do docker stack deploy -c docker-compose.yml postgres_test, but when i try to connect to 45.77.46.240(my host machine ip):8282(adminer port) from another machine it response with a 'ERR_CONNECTION_TIMED_OUT'

I wonder why can i connect to the visualizer on port 8080 it worked but not on the adminer?

Here my docker-compose.yml

version: "3"
services:
adminer:
   image: adminer
   restart: always
   ports:
     - "8282:8282"
db:
   image: postgres
   networks:
     - webnet
   environment:
     POSTGRES_PASSWORD: 123
     POSTGRES_USER: postgres
     POSTGRES_DB: real_estate
   volumes:
     - ./init.sql:/docker-entrypoint-initdb.d/init.sql
web:
   # replace username/repo:tag with your name and image details
   image: my_user_name/test_image:image1
   ports:
     - "8081:8081"
   networks:
     - webnet
   environment:
     DB_HOST: db
visualizer:
   image: dockersamples/visualizer:stable
   ports:
     - "8080:8080"
   volumes:
     - "/var/run/docker.sock:/var/run/docker.sock"
   deploy:
      placement:
        constraints: [node.role == manager]
   networks:
     - webnet
networks:
  webnet:

This not working due to the port issue. You have configured it as 8282. Adminer default port is 8080 and you can't change adminer default port. Therefore give try with the following code.

version: "3"
services:
adminer:
   image: adminer
   restart: always
   ports:
     - "8282:8080"
db:
   image: postgres
   networks:
     - webnet
   environment:
     POSTGRES_PASSWORD: 123
     POSTGRES_USER: postgres
     POSTGRES_DB: real_estate
   volumes:
     - ./init.sql:/docker-entrypoint-initdb.d/init.sql
web:
   # replace username/repo:tag with your name and image details
   image: my_user_name/test_image:image1
   ports:
     - "8081:8081"
   networks:
     - webnet
   environment:
     DB_HOST: db
visualizer:
   image: dockersamples/visualizer:stable
   ports:
     - "8080:8080"
   volumes:
     - "/var/run/docker.sock:/var/run/docker.sock"
   deploy:
      placement:
        constraints: [node.role == manager]
   networks:
     - webnet
networks:
  webnet:

This is another answer to specific port on adminer docker

version: "3"
services:
adminer:
   image: adminer
   restart: always
   ports:
   - "8282:8282"
   command:
   - 'php'
   - '-S'
   - '[::]:8282'
   - '-t'
   - '/var/www/html'
   entrypoint:
   - 'entrypoint.sh'
   - 'docker-php-entrypoint'

there are few options for the solution, anyhow the problem is not related to docker.

you should look at it as a process running in a machine over port 8282. It is accessible only to the host machine. It is not exposed to the world

the most straightforward solution is using ssh tunnel

https://www.ssh.com/ssh/tunneling/example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM