我每天在启动之前都必须删除 Docker 容器。

huangapple go评论57阅读模式
英文:

I have to remove the docker container every day before to starting

问题

I can provide the translation for the non-code part of your text:

"我正在开发一个应用程序,它使用Docker,每天我都会使用以下命令启动容器:

docker run --env-file ..env -e REDIS_HOST=stredis -v C:\inetpub\einvoice-connect\src:/var/www/eic -p 443:8443 -d --name eicapp eic:latest

问题是,远程桌面每天都会重新启动,所以我不得不再次启动容器,但当我想启动时,会出现以下消息:

docker: Error response from daemon: Conflict. The container name
"/eicapp" is already in use by container
"e4a36b85e15567ca1b69cf6de87e76d03ddee6aca069f74503601cd3d284c98c".
You have to remove (or rename) that container to be able to reuse that
name.

因此,我不得不删除容器,然后每天重新启动并配置容器。

有没有办法启动容器而不删除它?"

英文:

I'm working an app that it has docker and every day I started the container with

docker run --env-file ..env -e REDIS_HOST=stredis -v C:\inetpub\einvoice-connect\src:/var/www/eic -p 443:8443 -d --name eicapp eic:latest

the problem is that the remote desktops is restarted every day, so I have to start the container again but when I want to start I got the message:

> docker: Error response from daemon: Conflict. The container name
> "/eicapp" is already in use by container
> "e4a36b85e15567ca1b69cf6de87e76d03ddee6aca069f74503601cd3d284c98c".
> You have to remove (or rename) that container to be able to reuse that
> name.

So I have to remove the container, started again and config the container every day.

Is there a way to start the container without removed?

答案1

得分: 1

当您启动容器时,在您的命令中添加重启选项 --restart

docker run --restart=unless-stopped --env-file ..env -e REDIS_HOST=stredis -v C:\inetpub\einvoice-connect\src:/var/www/eic -p 443:8443 -d --name eicapp eic:latest

根据Docker文档unless-stopped选项的意思是:“无论退出状态如何,包括在守护进程启动时,始终重新启动容器,除非在停止Docker守护进程之前将容器置于停止状态。”

我建议使用 --restart=unless-stopped,这样您可以跟踪是否出现问题。否则,如果使用 always 策略,容器会无限重启,无论是否发生错误。

英文:

When you start the container, add the restart option --restart to your command:

docker run --restart=unless-stopped --env-file ..env -e REDIS_HOST=stredis -v C:\inetpub\einvoice-connect\src:/var/www/eic -p 443:8443 -d --name eicapp eic:latest

From the Docker documentation, unless-stop option means: "always restart the container regardless of the exit status, including on daemon startup, except if the container was put into a stopped state before the Docker daemon was stopped."

I suggest to use --restart=unless-stopped so you can keep track if something goes wrong. Othervise, if you use the always policy it keeps restarting forever regardless if errors happen.

huangapple
  • 本文由 发表于 2023年5月24日 18:49:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76322701.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定