-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
為什麼web這樣的config 能知道要連到哪一個db #4
Comments
因為 docker 可以透過容器的 service 連線到對應的 db, 我這邊剛好定義為 "db". 透過內建的 DNS 伺服器,可以直接使用容器名稱,就可解析出 IP,不需要再使用 IP 讓容器互相 |
那 web 裡 有支program code 要query 某個db , 要怎麼寫連線字串 ? 沒有db 的 ip ?
twtrubiks <notifications@github.com> 於 2020年12月11日 週五 上午11:50寫道:
… 因為 docker 可以透過容器的 service 連線到對應的 db, 我這邊剛好定義為 "db".
可參考 https://github.com/twtrubiks/docker-tutorial#user-defined-networks
透過內建的 DNS 伺服器,可以直接使用容器名稱,就可解析出 IP,不需要再使用 IP 讓容器互相
溝通,我們只需要知道容器的名稱就可以連接到容器。
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#4 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEWJVNZHRMK2EYEHL7B7U7DSUGJGTANCNFSM4USZLKPQ>
.
--
Huang Jie Qi _ JKHCG
|
我在 https://github.com/twtrubiks/docker-swarm-tutorial/blob/master/docker-swarm-secrets/api/django_rest_framework_tutorial/settings.py 這邊也是直接填入容器的名稱 (db). DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': secret('my_password'),
'HOST': 'db',
'PORT': 5432,
}
} 不知道你問的是不是這個? 假如你有很多db, 理論上應該也會透過一些方法同步每一顆的db, 所以應該隨便拿一顆(應該 host 直接填入 db 即可). |
swarm 時 為什麼web這樣的config 能知道要連到哪一個db (ip:port) ,
web 連線db 的設定值並沒有看見?
web:
image: twtrubiks/my_swarm_secrets_demo
ports:
- "8000:8000"
networks:
- backend
deploy:
replicas: 4
update_config:
parallelism: 2
restart_policy:
condition: on-failure
secrets:
- my_password
depends_on:
- db
The text was updated successfully, but these errors were encountered: