Search code examples
dockerubuntu

Docker desktop install in container fails on /etc/hosts .. what do to?


I am trying to install docker engine inside a container.

wget https://desktop.docker.com/linux/main/amd64/docker-desktop-4.16.2-amd64.deb
apt-get install -y ./docker-desktop-4.16.2-amd64.deb

Everything goes fine until in the post install phase, it tries to update /ect/hosts files for the kubernetes. Here it fails:

/var/lib/dpkg/info/docker-desktop.postinst: line 42: /etc/hosts: Read-only file system

This is expected behaviour for docker build in that it does not allow to modify /etc/hosts of the container.

Is there a way to solve this? Install docker desktop without doing this step? Or any other way?


Solution

  • I solved this issue by adding this parameter in build:

    --add-host kubernetes.docker.internal:127.0.0.1

    Example:

    docker build \
        --add-host kubernetes.docker.internal:127.0.0.1 \
        -t stsjava2 .