How to set docker container host name

When we start a new container, the default host name is the container’s id. This host name is not only easy to remember, but also inconvenient to use in production environments.

We can use the following options to specify the new container name and host name.

➜  ~ docker run -i -t --name u-lnmp-ccc -h u-lnmp-ccc ccc6e87d482b /bin/bash

docker run
-t Allocate a pseudo-TTY
-i Keep STDIN open even if not attached
-h, –hostname string  Container host name
–name string  Assign a name to the container

Add a Comment

Your email address will not be published. Required fields are marked *