如何设置容器名称作为计算机名称的容器?
How can I setup a container with container name as computer name?
例如,当我登录到我的容器时
docker exec -it vuejs_ci bash
root@3dc77c3403c8:/#
它使用容器 ID 3dc77c3403c8
作为计算机名称。当我设置我的容器时,我怎样才能做到 root@container_name
?
无法通过 docker exec
命令,但使用 docker run
命令,您可以传递 --hostname <name>
来设置容器的主机名。
$ docker run -it --hostname container_name ubuntu:18.04 bash
root@container_name:/#
root@container_name:/# echo $HOSTNAME
container_name
root@container_name:/# hostname
container_name
默认情况下,容器使用容器 ID 作为主机名。来自 https://docs.docker.com/config/containers/container-networking/#ip-address-and-hostname:
In the same way, a container’s hostname defaults to be the container’s
ID in Docker. You can override the hostname using --hostname.
例如,当我登录到我的容器时
docker exec -it vuejs_ci bash
root@3dc77c3403c8:/#
它使用容器 ID 3dc77c3403c8
作为计算机名称。当我设置我的容器时,我怎样才能做到 root@container_name
?
无法通过 docker exec
命令,但使用 docker run
命令,您可以传递 --hostname <name>
来设置容器的主机名。
$ docker run -it --hostname container_name ubuntu:18.04 bash
root@container_name:/#
root@container_name:/# echo $HOSTNAME
container_name
root@container_name:/# hostname
container_name
默认情况下,容器使用容器 ID 作为主机名。来自 https://docs.docker.com/config/containers/container-networking/#ip-address-and-hostname:
In the same way, a container’s hostname defaults to be the container’s ID in Docker. You can override the hostname using --hostname.