如何运行码头图像作为单身人士 [英] How to run docker image as singleton
问题描述
我有一个我想要运行的图像,但是我想要docker来看看这个图像是否已经从另一个终端运行...如果它正在运行,我不想要加载另一个...
这是可以使用docker吗?
如果它有帮助,我以特权模式运行码头服务器。
我试图搜索单码头码头这样的事情,但没有运气。
updates-
1.从ubuntu工作。
我的场景 - 从终端XI运行 docker运行Image_a
从终端YI运行 docker运行Image_a
尝试从终端Y运行时,我希望docker检查是否已经有一个Docker运行Image_a,答案是真的 - 我希望docker不运行在终端Y
您可以使用以下docker命令来获取从特定映像运行的所有容器:
docker ps --filter ancestor =imagename:tag
示例:
docker ps --filter ancestor =drone / drone:0.5
示例输出:
CONTAINER ID IMAGE COMMAND创建状态端口名称
3fb00087d4c1无人机/无人机:0.5/无人机代理6天前上26分钟8000 / tcp drone_drone-agent_1
这种方法使用docker api和docker守护程序,所以运行命令在后台或其他终端中执行也不重要。 / p>
另一种方法:
如果您单个容器形成单个图像:
尝试命名您的容器,您不能有两个同名的容器:
docker run - -name uniquecontainer Image_a
下次运行上述命令时,您将收到错误。 Btw考虑使用 -d
,所以你不必切换终端。
码头运行-d - 名称uniquectainer Image_a
I'm new to docker.
I have an image that I want to run, but I want docker to see if that image is already running from another terminal...if it is running I don't want it to load another one...
is this something that can be done with docker?
if it helps, I'm running the docker with a privileged mode.
I've tried to search for singleton docker or something like that, but no luck.
updates-
1.working from ubuntu.
My scenario- from terminal X I run docker run Image_a
from terminal Y I run docker run Image_a
when trying to run from terminal Y, I want docker to check if there is already a docker running with Image_a, and the answer is true - I want docker not to run in terminal Y
You can use the following docker command to get all containers that running from specific image:
docker ps --filter ancestor="imagename:tag"
Example:
docker ps --filter ancestor="drone/drone:0.5"
Example Output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3fb00087d4c1 drone/drone:0.5 "/drone agent" 6 days ago Up 26 minutes 8000/tcp drone_drone-agent_1
This approach uses docker api and docker daemon, so it doesnt matter if the run command executed in background or other terminal.
Aother approach:
If you have a single container form a single image:
Try naming your containers, You cant have 2 containers with the same name:
docker run --name uniquecontainer Image_a
Next time you run the above command you will get an error. Btw consider using -d
so you dont have to switch terminals.
docker run -d --name uniquecontainer Image_a
这篇关于如何运行码头图像作为单身人士的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!