How To Name a Docker Container Hostname

We all know how to name a Docker container using the –Name switch, but how do you name the actual container hostname? This post will show you how to do that.

Hostname

Some applications require hostnames of containers to be consistent or specific for applications to work or for business processes to work correctly.

Luckily, Docker CLI has a solution to that, as you will see in the code below.

The following example. Creates a docker container and set the container’s hostname to host1.

docker run -it -h host1  ubuntu /bin/bash

Published
Categorized as Docker

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.