例如,這裏是我的項目結構:碼頭工人組成:
project
|
+-- docker-compose.yml
|
+-- hq-backend
| +-- Dockerfile
| +-- .env.docker-compose
這裏是我的搬運工撰寫文件:
db:
container_name: hq-db
image: postgres:latest
ports:
- "5432:5432"
environment:
POSTGRES_USER: user_name
POSTGRES_PASSWORD: password
POSTGRES_DB: db_name
mongo:
container_name: hq-mongo
image: mongo:3.2.9
tty: true
stdin_open: true
ports:
- "27027:27027"
volumes:
- mongo:/data/db
hq-backend:
env_file:
- ../hq-backend/.env.docker_compose
build: ../hq-backend/
dockerfile: Dockerfile
ports:
- "8686:8686"
volumes:
- ".:/webapp"
links:
- db
- mongo
當我試圖運行docker-compose up
。我總是在年底達到此異常:
ERROR: for hq-backend Cannot start service hq-backend: Cannot link to a non running container: /hq-mongo AS /project_hq-backend_1/mongo
這裏是我的環境文件:
ENV=dev
DB_HOST=db
DB_ADDRESS=db
DB_PORT=5432
POSTGRES_DB=db_name
POSTGRES_USER=username
POSTGRES_PASSWORD=password
DB_MONGO_ADDRESS=mongo
DB_MONGO_PORT=27027
此問題僅與蒙戈服務,而不是數據庫服務。之後,如果我試圖再次運行docker-compose up
,沒有發現錯誤,但我的hq-backend
會拋出異常,因爲無法連接到mongo db。換句話說,我從零開始重建hq-backend
時遇到了這個問題。
請告訴我這個問題。