问题描述
当我尝试运行 python 图像时:
@H_502_3@docker run --name pytana -p 5050:5050 -it --network city pythonbac
出现错误
@H_502_3@peewee.OperationalError: Could not translate host name "db_container_name" to address: Name or service not kNown
源中有连接
@H_502_3@db = PostgresqlDatabase('postgres',user='postgres',password='postgres',host='db_container_name',port=5432)
docker 文件
@H_502_3@FROM python:3-onbuild EXPOSE 5050 CMD ["python","./app.py"]
db docker 撰写文件
@H_502_3@# This configuration is intended for development purpose,it's **your** responsibility to harden it for production version: '3.8' services: postgresql: image: postgres:13.1 volumes: - testdataloc:/var/lib/postgresql/data/ environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres container_name: db_container_name networks: - city # If you want to expose these ports outside your dev PC,# remove the "127.0.0.1:" prefix ports: - 5432:5432 volumes: testdataloc: external: true networks: city: # Use a custom driver driver: bridge
我的操作系统 wind10。 当我使用网络主机并将主机连接到本地主机时的附加信息。
@H_502_3@docker network inspect city [ { "Name": "city","Id": "1734484676b63915c041bc0128d1a5b9d340cb4b76878eb54e11ea7995c0e1de","Created": "2021-03-10T14:27:03.6343643Z","Scope": "local","Driver": "bridge","EnableIPv6": false,"IPAM": { "Driver": "default","Options": {},"Config": [ { "subnet": "172.19.0.0/16","Gateway": "172.19.0.1" } ] },"Internal": false,"Attachable": false,"Ingress": false,"ConfigFrom": { "Network": "" },"ConfigOnly": false,"Containers": {},"Labels": {} } ]
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)