2

I am trying to understand how I access containers between each other through their container name. Specifically when using a pgadmin container and connecting to a postgresql container through dns.

In docker-compose V3 , I cannot link them, nor does networks: seem to be available either.

The main reason to need this is when the containers spin up they don't have a static IP address, so in pgadmin I can't connect to the postgresql DB using the same IP every time , so a dns name would work better (ie: the container name).

Can we do this with docker-compose or at least set a static ip address for a specific container?

I have tried creating a user defined network:

networks:
  backed:

and then using it in the service:

app:
  networks:
    - backend

This causes a docker-compose error regarding an invalid option of "networks" in the app.

docker-compose.yml

version: "0.1"

services:
  devapi:
    container_name: devapi
    restart: always
    build: .
    ports:
      - "3000:3000"

  api-postgres-pgadmin:
    container_name: api-postgres-pgadmin
    image: dpage/pgadmin4:latest
    ports:
      - "5050:80"
    environment:
      - [email protected]
      - PGADMIN_DEFAULT_PASSWORD=12345

  api-postgres:
    container_name: api-postgres
    image: postgres:10
    volumes:
      - ./data:/data/db
    ports:
      - "15432:5432"
    environment:
      - POSTGRES_PASSWORD=12345
2
  • 1
    Can you clarify this sentence more "I am trying to understand how I access containers between each other through their container name. "? Also, why can't you use the host-name to communicate between containers? Commented Apr 12, 2019 at 2:11
  • 1
    Also, your example docker-compose.yml doesn't show your (attempted) use of networks. Can you update it to include that? It might highlight why you're seeing that error. Commented Apr 12, 2019 at 2:12

2 Answers 2

2

Actually, I spot one immediate problem:

version: "0.1"

Why are you doing this? The current version of the compose file format is 3.x. E.g:

version: "3"

See e.g. the Compose file version 3 reference.

The version determines which feature are available. It's entirely possible that by setting version: "0.1" you are explicitly disabling support for the networks parameter. You'll note that the reference shows examples using the networks attribute.

As an aside, unless there is a particular reason you ened it, I would drop the use of the container_name in your compose file, since this makes it impossible to run multiple instances of the same compose file on your host.

Sign up to request clarification or add additional context in comments.

Comments

0

networks are available from docker-compose version 3 but you are using version:"0.1" in your docker-compose file.

Change the version: "0.1" to version: "3" in docker-compose.yml.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.