vectordotdev/vector · warning
Invalid value in $DOCKER_HOST
Error message
Invalid value in $DOCKER_HOST
What it means
vdev's detect_docker_socket reads the DOCKER_HOST environment variable and expects it to be valid UTF-8 (into_string().expect("Invalid value in $DOCKER_HOST")) and then a unix:// socket path. If DOCKER_HOST is set to a non-UTF-8 value, the first expect panics; this is distinct from the follow-up panic for non-unix:// values. The function only supports local unix sockets, not TCP Docker hosts.
Solutions
- Inspect the variable: `printf '%s' "$DOCKER_HOST" | xxd` to spot invalid bytes, then unset it (`unset DOCKER_HOST`) to fall back to /var/run/docker.sock.
- Set DOCKER_HOST to a clean value such as unix:///var/run/docker.sock.
- Check ~/.bashrc, ~/.zshrc, or CI config for a script that writes a malformed DOCKER_HOST and fix it.
- In code, replace the expect with from_utf8 handling on the OsString and a clear anyhow error, or support tcp:// hosts instead of assuming unix://.
Example fix
// before
Some(host) => host
.into_string()
.expect("Invalid value in $DOCKER_HOST")
// after
Some(host) => host.into_string().map_err(|bad|
anyhow!("$DOCKER_HOST is not valid UTF-8: {:?}", bad)
)? Defensive patterns
Strategy: validation
Validate before calling
# before running vdev
python3 -c "import os,sys; v=os.environ.get('DOCKER_HOST',''); v.encode('utf-8'); sys.exit(0 if (not v or v.startswith('unix://')) else 1)" || { echo 'DOCKER_HOST must be UTF-8 unix:// socket path'; exit 1; } Try / catch
match env::var_os("DOCKER_HOST") {
Some(host) => match host.into_string() {
Ok(s) => /* proceed, validate unix:// prefix */,
Err(bad) => return Err(anyhow!("$DOCKER_HOST is not valid UTF-8: {:?}", bad)),
},
None => /* default socket */,
} Prevention
- Unset DOCKER_HOST to use the default /var/run/docker.sock when unsure.
- Set DOCKER_HOST to unix:///var/run/docker.sock explicitly in profiles/CI.
- Audit shell startup files and CI env exports for malformed values.
- Remember this helper supports only unix sockets — avoid tcp:// values when using vdev.
When it happens
Trigger: Having DOCKER_HOST exported with non-UTF-8 bytes in the value (e.g. mangled by a shell/profile script), then running any vdev command that resolves the Docker socket.
Common situations: DOCKER_HOST set by tooling (docker-machine, docker context) with unexpected content; corrupted shell profile exporting garbage; copy-pasted value with invisible/non-UTF-8 characters.
Understand the failure class
Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.
Related errors
- Invalid config file name
- all json-file keys should be matched
- Failed to convert OsStr to &str for
- Integration has no environments
- not a valid path
AI-assisted analysis of vectordotdev/vector@bdb87aeaa4 (2026-09-16).
Data as JSON: /api/errors/2cb368a8fb488d9c.
Report an issue: GitHub.
Appendix: source
Thrown at vdev/src/testing/docker.rs:40
if Command::new(tool)
.arg("version")
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.and_then(|mut child| child.wait())
.is_ok_and(|status| status.success())
{
return OsString::from(String::from(tool));
}
}
fatal!("No container tool could be detected.");
}
fn detect_docker_socket() -> PathBuf {
match env::var_os("DOCKER_HOST") {
Some(host) => host
.into_string()
.expect("Invalid value in $DOCKER_HOST")
.strip_prefix("unix://")
.expect("$DOCKER_HOST is not a socket path")
.into(),
None => "/var/run/docker.sock".into(),
}
}
View on GitHub (pinned to bdb87aeaa4)