Skip to content

Commit 89cfb5f

Browse files
authored
Merge pull request #1361 from t-woerner/infra_image_start_fix_hosts
infra/image/shcontainer: Add host entry in container_start
2 parents 0d9b164 + 5fb2258 commit 89cfb5f

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

infra/image/shcontainer

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ container_start() {
5555

5656
log info "= Starting ${name} ="
5757
podman start "${name}"
58+
# Add host entry to /etc/hosts
59+
ip=$(podman inspect "${name}" --format "{{.NetworkSettings.IPAddress}}")
60+
hostname=$(podman inspect "${name}" --format "{{.Config.Hostname}}")
61+
if [ -n "${ip}" ] && [ -n "${hostname}" ]; then
62+
cmd=$(cat <<EOF
63+
sed -i -e "/[ \t]${hostname}/d" /etc/hosts
64+
echo -e "$ip\t${hostname} ${hostname%%.*}" >> /etc/hosts
65+
EOF
66+
)
67+
podman exec "${name}" bash -c "$cmd"
68+
fi
5869
# Ensure /etc/shadow is readable
5970
podman exec "${name}" bash -c "chmod u+r /etc/shadow"
6071
echo

0 commit comments

Comments
 (0)