1

In the docker-compose.yaml file created by Laravel Sail is an entry under a service's ports section reading FORWARD_REDIS_PORT.
I understand the short and long syntax of a service's ports section. But, have never seen a variable pre-pended with FORWARD_. What does this syntax mean? And how does it differ from using the short syntax for ports?

Example of Docker-Compose Ports short syntax

  redis:
    image: 'redis:alpine'
    ports:
      - '6379:6379'

Example of Docker-Compose from Laravel Sail

  redis:
    image: 'redis:alpine'
    ports:
      - '${FORWARD_REDIS_PORT:-6379}:6379'
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
MikeyE
  • 1,756
  • 1
  • 18
  • 37

1 Answers1

1

This is a variable, that can be defined in multiple ways, some of them are in an .env file, in the shell running the docker-compose command or added when running the command, like

FORWARD_REDIS_PORT=1234 docker-compose up

The :-6379 part is actually called bash parameter expansion and it defines a default to a variable if it was found undefined when used.
So, in your case, if your environment, shell, etc., does not define the variable FORWARD_REDIS_PORT, you will effectively end up mapping the port 6379 of your host to the port 6379 of your container.

This behaviour is described in the documentation page "Ways to set environment variables in Compose" and its chapter "Substitute from the shell".

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83