五月综合激情婷婷六月,日韩欧美国产一区不卡,他扒开我内裤强吻我下面视频 ,无套内射无矿码免费看黄,天天躁,日日躁,狠狠躁

新聞動態(tài)

Docker內(nèi)如何訪問本機(宿主機)的具體方法

發(fā)布日期:2022-03-24 18:41 | 文章來源:gibhub

Question

Docker內(nèi)需要訪問本機的數(shù)據(jù)庫,如何訪問。使用127.0.0.1肯定是不行的,因為這個在Docker容器里面指的是容器本身。所以,需要走別動渠道進行解決。

Solution

下面幾種辦法,根據(jù)操作系統(tǒng)的類型,選取其一即可。

DockerFile:

RUN /sbin/ip route|awk '/default/ { print $3,"\tdockerhost" }' >> /etc/hosts

RunTime:

(may not use) docker run --add-host dockerhost:`/sbin/ip route|awk '/default/ { print $3}'` [my container]
(useful) docker run --add-host=dockerhost:`docker network inspect --format='{{range .IPAM.Config}}{{.Gateway}}{{end}}' bridge` [IMAGE]

Docker for Mac (17.12+):

docker.for.mac.host.internal
MONGO_SERVER=docker.for.mac.host.internal
# docker-compose.yml
version: '3'
services:
 api:
  build: ./api
  volumes:
   - ./api:/usr/src/app:ro
  ports:
   - "8000"
  environment:
   - MONGO_SERVER
  command: /usr/local/bin/gunicorn -c /usr/src/app/gunicorn_config.py -w 1 -b :8000 wsgi

Linux

# Solution 1
/sbin/ip route|awk '/default/ { print $3 }'
docker run --add-host dockerhost:`/sbin/ip route|awk '/default/ { print $3}'` [my container]
# Solution 2
-e "DOCKER_HOST=$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')"

Principle

想知道原理,需要了解計算機網(wǎng)絡的模型和docker實現(xiàn)的模型。docker內(nèi)部實際上實現(xiàn)了一個虛擬網(wǎng)橋docker0,需要通過網(wǎng)橋找到外部宿主機的在網(wǎng)橋的虛擬地址,也就是docker.for.mac.host.internal,就可以實現(xiàn)容器內(nèi)訪問外部宿主機。感興趣的話可以了解下Docker的網(wǎng)絡原理、計算機網(wǎng)絡原理和docker compose等內(nèi)容。

Reference

[1].(stackoverflow)insert-docker-parent-host-ip-into-containers-hosts-file

[2].(stackoverflow)how-to-get-the-ip-address-of-the-docker-host-from-inside-a-docker-container

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持本站。

版權(quán)聲明:本站文章來源標注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務器上建立鏡像,否則將依法追究法律責任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實時開通

自選配置、實時開通

免備案

全球線路精選!

全天候客戶服務

7x24全年不間斷在線

專屬顧問服務

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務熱線

關(guān)注
微信

關(guān)注官方微信
頂部