0
考虑下面的码头工人,compose.test.yml文件:在测试使用Postgres的图像
version: '2'
services:
sut:
build: .
command: nosetests
environment:
- DJANGO_SETTINGS_MODULE=test.settings
links:
- db
db:
image: postgres
expose:
- 5432
构建SUT容器
docker-compose -f docker-compose.test.yml build sut
运行容器:
[email protected]:~/github/djlobnek$ docker-compose -f docker-compose.test.yml run sut /bin/bash
[email protected]:/djlobnek# psql -h localhost -U postgres
psql: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
**could not connect to server: Connection refused**
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
我使用{docker-compose -f docker-compose.test.yml run sut/bin/bash}直接连接到sut层。我已经在dockerfile中安装了postgresql-client。运行{psql -h localhost -U postgres}不成功 – tschm
确实,了解了localhost问题。我现在确实可以连接到容器,并且可以使用psql启动postgres命令行,例如, thomas @ linuxclientlobnek01:〜/ github/djlobnek $ docker-compose -p test -f docker-compose.test.yml运行sut/bin/bash root @ 245ad3d10a9b:/ djlobnek#psql -h db -U postgres该工作,然而... – tschm
当然,重点是自动化这一点,在这里我仍然面临问题。所以注意我的命令有多类似:docker-compose -p test -f docker-compose.test.yml运行sut。在这里,测试失败,上述被拒绝的连接相同 – tschm