diff --git a/30-add-host-ip-entry.sh b/30-add-host-ip-entry.sh index 50dc6f2898e2204389089c0335ebc80d3581264e..b5b462e40ed4475c147f1c64d9ed13eaf5bca1a0 100755 --- a/30-add-host-ip-entry.sh +++ b/30-add-host-ip-entry.sh @@ -1,3 +1,9 @@ #!/bin/bash -HOST_IP=$(/sbin/ip route|awk '/default/ { print $3 }') -echo "$HOST_IP host.docker.internal" >> /etc/hosts +if [ "$EUID" -ne 0 ] + then + HOST_IP=$(sudo /sbin/ip route|awk '/default/ { print $3 }') + echo "$HOST_IP host.docker.internal" >> /etc/hosts + else + HOST_IP=$(/sbin/ip route|awk '/default/ { print $3 }') + sudo -s "echo '$HOST_IP host.docker.internal' >> /etc/hosts" +fi diff --git a/Dockerfile b/Dockerfile index 2f344a6002caca582209ed68bdf5f28e0cf6d184..104e8cefbcf817eec9ffac9779e5bd9312035bc4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,8 +13,7 @@ COPY 30-add-host-ip-entry.sh /docker-entrypoint.d/30-add-host-ip-entry.sh COPY docker-run.sh /docker-run.sh RUN mkdir -p /docker-run.d RUN chmod a+x /docker-entrypoint.sh && \ - chmod a+x /docker-run.sh && \ - chmod a+w /etc/hosts + chmod a+x /docker-run.sh ENTRYPOINT [ "/docker-entrypoint.sh" ] CMD [ "/docker-run.sh" ]