In docker-compose how to create an alias / link to localhost?

I think the correct answer is from

Aliases can be defined as part of the network declaration for a service. See aliases in Compose file reference for more details on that. – King Chung Huang Apr 24 ’17 at 15:18

here is the example from the doc

version: '2'

services:
  web:
    build: ./web
    networks:
      - new

worker:
  build: ./worker
  networks:
    - legacy

db:
  image: mysql
  networks:
    new:
      aliases:
        - database
    legacy:
      aliases:
        - mysql

networks:
  new:
  legacy:

you can access the db in this docker-compose, also you can use mysql to connect this db

Leave a Comment

File not found.