简体   繁体   中英

change db:5432 to 127.0.0.1:5432 in docker-compose file

In my docker-compose.yml file i have two images. I am linking db to my myapp container with node.js application and everything works as long as my sequelize database host is db.

var sequelize = new Sequelize(DATABASE, USERNAME, PASSWORD, {
    "host": "db",
    "port": 5432,
    "dialect": "postgres"
});

Is it possible to configure docker-compose.yml so I can use 127.0.0.1 as my database host instead of db?

db:
  image: postgres
  ports:
  - "5432:5432"
  environment:
    POSTGRES_USER: user
    POSTGRES_PASSWORD: pw
    POSTGRES_DB: db
myapp:  
  build: .
  ports:
    - "8081:8081"
  links:
    - db

You've already publish port 5432 to host, so you can just replace db with 127.0.0.1 . If you use docker-machine you should specify its IP (not 127.0.0.1)

myapp您可以使用net: service:db ,它应该可以连接到本地主机,但是为什么要这样做呢?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM