FG
☁️ Cloud & DevOpsDocker

Switch to using hyphens as a separator in hostnames

Freshover 4 years ago
Mar 14, 20260 views
Confidence Score86%
86%

Problem

The hostname format used by fig creates names that are not strictly valid. Current pseudo-code: [code block] This generates names like `cluster_hadoop_1`. Underscores are not valid (though in practice _most_ components are tolerant of this). Valid names should match `[a-zA-Z0-9\-]+`. I came across this error when trying to test out some hadoop/hdfs containers and hadoop bailed with an exception saying that `hdfs://flume_hadoop_1/` was not valid URI (even though it was in `/etc/hosts` and `ping flume_hadoop_1` worked just fine). See: http://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names Changing this to dashes is easy, but it would break existing configurations that depend on hard coded container names.

Error Output

error when trying to test out some hadoop/hdfs containers and hadoop bailed with an exception saying that `hdfs://flume_hadoop_1/` was not valid URI (even though it was in `/etc/hosts` and `ping flume_hadoo

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Moderate Confidence Fix
84% confidence100% success rate2 verificationsLast verified Mar 14, 2026

Solution: Switch to using hyphens as a separator in hostnames

Low Risk

Frustratingly, underscores are invalid in hostnames, and dashes are invalid in shell variable names. So if you can't name a Docker link without either breaking one of those or smushing everything together (e.g. `hadoop1`). Not ideal. However, looks like https://github.com/docker/docker/pull/6270 might fix this by sanitising environment variable names, in which case Fig can switch to dashes and ev

84

Trust Score

2 verifications

100% success
  1. 1

    Frustratingly, underscores are invalid in hostnames, and dashes are invalid in s

    Frustratingly, underscores are invalid in hostnames, and dashes are invalid in shell variable names. So if you can't name a Docker link without either breaking one of those or smushing everything together (e.g. `hadoop1`). Not ideal.

    text
    ``` bash
    $ fig run web cat /etc/hosts
    ...
    172.17.0.42 hadoop-1
    ...
    
    $ fig run web env
    ...
    HADOOP_1_PORT=tcp://172.17.0.42:5432
    HADOOP_1_PORT_5432_TCP=tcp://172.17.0.42:5432
    HADOOP_1_PORT_5432_TCP_ADDR=172.17.0.42
    ...
  2. 2

    However, looks like https://github.com/docker/docker/pull/6270 might fix this by

    However, looks like https://github.com/docker/docker/pull/6270 might fix this by sanitising environment variable names, in which case Fig can switch to dashes and everything will hopefully work:

Validation

Resolved in docker/compose GitHub issue #229. Community reactions: 1 upvotes.

Verification Summary

Worked: 2
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

dockerdocker-composecontainers