我在C#中使用我的简单应用程序与postgresql连接.
我想用这个应用程序创建图像,然后用docker运行.
我使用时一切正常:
$docker build
$docker run postgres
$docker run my_app
另外,当我从应用程序目录使用compose时,一切都还可以:
$docker-compose build
$docker-compose up
但有没有机会使用docker-compose为我之前建立的图像?
我想将此图像发布到我的仓库,我的团队中的其他人只需下载并运行此图像(应用程序数据库).
当我进行compose-build和next compose运行my_app时,我在连接数据库时遇到异常:
dbug: Npgsql.NpgsqlConnection[3]
opening connection to database 'POSTGRES_USER' on server 'tcp://postgres:5432'.
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.AggregateException: One or more errors occurred. (No such device or address) ---> System.Net.Internals.socketExceptionFactory+ExtendedSocketException: No such device or address
我当前的docker-compose.yml文件:
version: '2'
services:
web:
container_name: 'postgrescoreapp'
image: 'postgrescoreapp'
build:
context: .
dockerfile: Dockerfile
volumes:
- .:/var/www/postgrescoreapp
ports:
- "5001:5001"
depends_on:
- "postgres"
networks:
- postgrescoreapp-network
postgres:
container_name: 'postgres'
image: postgres
environment:
POSTGRES_PASSWORD: password
networks:
- postgrescoreapp-network
networks:
postgrescoreapp-network:
driver: bridge
解决方法:
您应该使用以下名称构建映像:(registryName:RegistryPort)/ imagename:version
$docker build -t myRegistry.example.com:5000/myApp:latest .
$docker build -t myRegistry.example.com:5000/myDb:latest .
Myapp:
image: myRegistry.example.com:5000/myApp:latest
MyDb:
image: myRegistry.example.com:5000/myDb:latest
然后推它:
$docker push myRegistry.example.com:5000/myApp:latest
$docker push myRegistry.example.com:5000/myDb:latest
你的伙伴现在应该能够拉它
$docker pull myRegistry.example.com:5000/myApp:latest
$docker pull myRegistry.example.com:5000/myDb:latest
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。