0
version: '1'

services:

  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_PASSWORD: mtuser
      POSTGRES_USER: mtpass
    

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

This is my docker compose file. There is no error while it is compiling and no trouble on docker desktop, all containers are running.

But I can't connect to Postgresql with pgAdmin or .net core connection.

But i can connect via adminer v4.8.1

1 Answer 1

1

First of all, is there any particular reason why you're using compose file format version: '1'? You should at least use version: '2', or there will be compatibility issues. See the compatibility table here.

About your question: Your 'db' postgres service, is not exposing any port, nor are you mapping the postgres db ports from the container to the host machine. Therefor, you cannot access it from any external service, outside the docker network. Adminer can connect, because it is in the same docker network. But it shouldn't be possible with newer compose file formats, because again, you are not exposing any port on 'db' service.

The file should look something like this:

version: '2'

services:

  db:
    image: postgres
    restart: always
    ports:
      - "5432:5432"  #<- Postgres Db port mapped to host machine.
    environment:
      - POSTGRES_PASSWORD=mtuser
      - POSTGRES_USER=mtpass
    

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.