"docker ps" 输出的 NAMES 列
NAMES column of "docker ps" output
下面是 docker 文件:
FROM golang:1.14.10
MAINTAINER xyz
ENV SOURCES /product-api
COPY . ${SOURCES}
WORKDIR /product-api
RUN make swagger
ENTRYPOINT product-api
在 运行 之后执行以下命令:
$ docker build -t cloud-native-product-api:1.0.0
$ docker run -it -p 8080:8080 cloud-native-product-api:1.0.0
docker ps
给出以下输出:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9aa144b7873c cloud-native-product-api:1.0.0 "/bin/sh -c product-…" 3 minutes ago Up 3 minutes 0.0.0.0:9090->9090/tcp trusting_matsumoto
trusting_matsumoto
列中的值 trusting_matsumoto
来自哪里?
除非您为容器指定名称,否则 docker 会随机分配一个。
您可以使用 --name
参数指定容器名称:
$ docker run --rm -it --name my_alpine_container alpine
If you do not assign a container name with the --name
option, then the daemon generates a random string name for you. Defining a name can be a handy way to add meaning to a container. If you specify a name, you can use it when referencing the container within a Docker network. This works for both background and foreground Docker containers.
下面是 docker 文件:
FROM golang:1.14.10
MAINTAINER xyz
ENV SOURCES /product-api
COPY . ${SOURCES}
WORKDIR /product-api
RUN make swagger
ENTRYPOINT product-api
在 运行 之后执行以下命令:
$ docker build -t cloud-native-product-api:1.0.0
$ docker run -it -p 8080:8080 cloud-native-product-api:1.0.0
docker ps
给出以下输出:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9aa144b7873c cloud-native-product-api:1.0.0 "/bin/sh -c product-…" 3 minutes ago Up 3 minutes 0.0.0.0:9090->9090/tcp trusting_matsumoto
trusting_matsumoto
列中的值 trusting_matsumoto
来自哪里?
除非您为容器指定名称,否则 docker 会随机分配一个。
您可以使用 --name
参数指定容器名称:
$ docker run --rm -it --name my_alpine_container alpine
If you do not assign a container name with the
--name
option, then the daemon generates a random string name for you. Defining a name can be a handy way to add meaning to a container. If you specify a name, you can use it when referencing the container within a Docker network. This works for both background and foreground Docker containers.