0

I want to publish a port to my host from a container. The container is running in "host" network mode by rootless dockerd.

My question is: how to publish a port to my host from this container (run in a "host" network mode using rootless dockerd)?

Should I run dockerd-rootless.sh script or even a raw rootlesskit with specific arguments to achieve this goal?

I have done the following steps:

  1. Install a rootless dockerd on Ubuntu 20.04:

    $ curl -fsSL https://get.docker.com/rootless | sh
    $ export PATH=$HOME/bin:$PATH
    $ export DOCKER_HOST=unix:///run/user/$UID/docker.sock
    
  2. Run a rootless dockerd:

    $ dockerd-rootless.sh --experimental
    ...
    INFO[2020-06-03T16:53:51.690572434+02:00] API listen on /run/user/1000/docker.sock
    
  3. Check a container in a non-host network mode (SUCCESS):

    $ docker run --rm -it -p 8080:8080 python python -m http.server 8080
    Serving HTTP on 0.0.0.0 port 8080 (http://0.0.0.0:8080/) ...
    

    On other terminal:

    $ curl http://localhost:8080
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    ...
    
    $ lsof -i :8080
    COMMAND      PID    USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
    rootlessk 116618 marcinr    9u  IPv6 2313409      0t0  TCP *:http-alt (LISTEN)
    
  4. Try to run in a "host" network mode (FAILURE):

    $ docker run --rm -it --network host python python -m http.server 8080
    Serving HTTP on 0.0.0.0 port 8080 (http://0.0.0.0:8080/) ...
    

    On other terminal:

    $ curl http://localhost:8080
    curl: (7) Failed to connect to localhost port 8080: Connection refused
    
    $ lsof -i :8080
    <empty>
    

    I know I can run these commands using nsenter:

    $ nsenter -U -n -t $(cat /run/user/$UID/docker.pid) lsof -i :8080
    COMMAND    PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
    python  119656 root    3u  IPv4 2360676      0t0  TCP *:http-alt (LISTEN)
    

    but I want to be able to use my web application in a web browser, not in a terminal only.

0

--net=host is unsupported in Rootless as of Docker 19.03: https://docs.docker.com/engine/security/rootless/#networking-errors

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .