docker networking namespace not visible in ip netns list

前端 未结 3 986
一整个雨季
一整个雨季 2020-12-22 18:30

When I create a new docker container like with

docker run -it -m 560m --cpuset-cpus=1,2 ubuntu sleep 120

and check its namespaces, I can s

3条回答
  •  旧时难觅i
    2020-12-22 18:50

    Similar but different with @jary’s answer.
    There is no need to introduce /proc// or netster. Only one move below to achieve what you want. Thus, you could operate containers’ network namespace just like they are created manually on host machine.

    One Move:

    ln -s /var/run/docker/netns  /var/run/netns 
    

    Result:

    Start a container:

    docker run -tid ubuntu:18.04 
    

    List container:

    root@Light-G:/var/run# docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    972909a27ea1        ubuntu:18.04        "/bin/bash"         19 seconds ago      Up 18 seconds                           peaceful_easley
    

    List network namespace of this container:

    root@Light-G:/var/run# ip netns list
    733443afef58 (id: 0)
    

    Delete container:

    root@Light-G:/var/run# docker rm -f 972909a27ea1
    972909a27ea1
    

    List network namespace again:

    root@Light-G:/var/run# ip netns list
    root@Light-G:/var/run#
    

提交回复
热议问题