V
V
VegasChickiChicki2021-11-28 22:34:19
Docker
VegasChickiChicki, 2021-11-28 22:34:19

How to communicate between containers in docker-compose?

There is such a structure (docker-compose.yml):

version: "3"

services:
  client:
    container_name: client
    build: client/
    command: npm run dev
    env_file:
      - ".env"
    ports:
      - "${CLIENT_PORT}:${CLIENT_PORT}"
    volumes:
      - ./client:/client

  api:
    container_name: api
    build: api/
    command: npm run dev
    env_file:
      - ".env"
    volumes:
      - ./api:/api


I'm trying to understand how to make a request to api from the front, such a request does not work:
`//api:${process.env.API_PORT}`

I can't understand what's the matter...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2021-11-28
@VegasChickiChicki

You are making the request correctly. You are setting the environment variables incorrectly.
To set an environment variable within the container must do so Set environment variables in containers
̶P̶e̶r̶e̶m̶e̶n̶n̶y̶e̶ ̶v̶ ̶.̶e̶n̶v̶ ̶o̶n̶i̶ ̶d̶l̶ya̶ ̶d̶o̶c̶k̶e̶r̶-̶c̶o̶m̶p̶o̶s̶e̶, ̶ ̶a̶ ̶n̶e̶ ̶d̶l̶ya̶ ̶p̶r̶i̶l̶o̶zh̶e̶n̶i̶ya̶ ̶v̶ ̶k̶o̶n̶t̶e̶y̶n̶e̶r̶e̶.̶
̶N̶o̶ ̶t̶y̶ ̶m̶o̶zh̶e̶sh̶̶ ̶z̶a̶p̶o̶l̶n̶ya̶t̶̶ ̶p̶e̶r̶e̶m̶e̶n̶n̶y̶e̶ ̶v̶ ̶e̶n̶v̶i̶r̶o̶n̶m̶e̶n̶t̶: ̶ ̶i̶z̶ ̶.̶e̶n̶v̶
UPD
And there , still correct. You can pass variables from a file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question