docker-compose deploy error when set two containers with the same image
error description
Deploying two container with the same image in a server, when run “docker-compose up -d” for the 1st container, the 1st container works fine. However, when activate the 2nd container, it makes the 1st container doesn’t work anymore.
在一個伺服器,利用同一個image佈署2個container. 以”docker-compose up -d”啟動第一個container, 第一個container運作正常。當啟動第二個container時,第一個container的功能就會失效。
solution
assign each container a “project name” will solve the problem.
- add “COMPOSE_PROJECT_NAME=1st container project name” in the “.env” file of 1st container
- add “COMPOSE_PROJECT_NAME=2nd container project name” in the “.env” file of 2nd container
幫每一個container指定一個 “project name” 可以解決這個問題。