如何从内部获取容器名称?码头工人.io [英] how to get container name from inside? docker.io

查看:29
本文介绍了如何从内部获取容器名称?码头工人.io的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从容器中获取 docker 的容器名称?

How can I get docker's container name from inside the container?

我不能使用检查";因为我必须使用容器内部的脚本从 JSON url 获取信息.

I can't use "inspect" because I have to use a script from inside the container to get information from a JSON url.

推荐答案

如果您的意思是容器 ID,它可以在 env 中作为主机名变量使用.它应该与大多数操作的名称互换.

If you mean the Container ID its available in the env as the hostname variable. It should be interchangeable with the name for most operations.

env
HOSTNAME=5252eb24b296
TERM=xterm
....

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
5252eb24b296        ubuntu:14.04        "bash"              23 seconds ago      Up 22 seconds                           test

这篇关于如何从内部获取容器名称?码头工人.io的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆