我克隆了原始 repo docker bookstack
我復制了原始的 Docker-compose。即使我不想更新到 3,希望事情會奏效。
version: "2"
services:
bookstack:
image: lscr.io/linuxserver/bookstack
container_name: bookstack
environment:
- PUID=1000
- PGID=1000
- APP_URL=
- DB_HOST=bookstack_db
- DB_USER=bookstack
- DB_PASS=*******
- DB_DATABASE=mystackapp
volumes:
- /path/to/data:/config
ports:
- 6875:80
restart: unless-stopped
depends_on:
- bookstack_db
bookstack_db:
image: lscr.io/linuxserver/mariadb
container_name: bookstack_db
environment:
- PUID=1000
- PGID=1000
- MYSQL_ROOT_PASSWORD=******
- TZ=Europe/Budapest
- MYSQL_DATABASE=mystackapp
- MYSQL_USER=bookstack
- MYSQL_PASSWORD=*******
volumes:
- /path/to/data:/config
restart: unless-stopped
但我仍然得到錯誤。
Creating network "docker-bookstack_default" with the default driver
WARNING: Found orphan containers (docker-bookstack_mysql_1) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
Creating bookstack_db ... done
Creating bookstack ... error
ERROR: for bookstack Cannot create container for service bookstack: Conflict. The container name "/bookstack" is already in use by container "ceede4ebfd4c16842e3a9486fd58b67713be6d527bc3ff2740a251172b2c5967". You have to remove (or rename) that container to be able to reuse that name.
我嘗試添加 -p 標志并指定我的專案。又出錯了!!
docker-compose -p firstproject up
Creating network "firstproject_default" with the default driver
Creating bookstack_db ... done
Creating bookstack ... error
ERROR: for bookstack Cannot create container for service bookstack: Conflict. The container name "/bookstack" is already in use by container "ceede4ebfd4c16842e3a9486fd58b67713be6d527bc3ff2740a251172b2c5967". You have to remove (or rename) that container to be able to reuse that name.
ERROR: for bookstack Cannot create container for service bookstack: Conflict. The container name "/bookstack" is already in use by container "ceede4ebfd4c16842e3a9486fd58b67713be6d527bc3ff2740a251172b2c5967". You have to remove (or rename) that container to be able to reuse that name.
ERROR: Encountered errors while bringing up the project.
為什么?這個 docker-compose 檔案是正確的嗎?在這種情況下我有回圈依賴嗎?
uj5u.com熱心網友回復:
錯誤訊息指出了問題以及如何解決它:
ERROR: for bookstack Cannot create container for service bookstack:
Conflict. The container name "/bookstack" is already in use by container "ceede4ebfd4c16842e3a9486fd58b67713be6d527bc3ff2740a251172b2c5967".
You have to remove (or rename) that container to be able to reuse that name.
問題是您對容器名稱進行了硬編碼,因此使用另一個專案名稱不會改變任何內容,容器名稱保持不變。
services:
bookstack:
container_name: bookstack
您需要洗掉容器,即使用docker compose downor docker rm bookstack。
我建議不要對容器名稱進行硬編碼以避免此問題和其他問題。這樣做沒有什么好處。
只需將其從您的 yaml 檔案中洗掉即可。
services:
bookstack:
image: lscr.io/linuxserver/bookstack
# other stuff without container name
然后,您還需要確保使用此名稱進行通信的任何其他服務都使用正確的名稱。由于您的 compose 服務名稱與舊的靜態容器名稱相同,因此無需進一步更改即可使用。
我還會container_name從 yaml 檔案中洗掉任何其他密鑰。即bookstack_db。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/460315.html
