How can i create a namespace in docker ENTRYPOINT?

128 Views Asked by At

I'm tryin to create a linux-namespace using unshare command in my docker

What i want to do: I want to create a namespace using unshare command in background mode in my docker container once it's ready I can do this by using commands manualy from inside the container like this:

unshare -rum & UNSHARE_NS_PID=$! # I use it's PID for other purposes later

Code above gives me desired result, it looks like this:

$ lsns
NS         TYPE   NPROCS PID USER COMMAND
4026531834 time        4   1 root /bin/sh -c /bin/bash bash
4026531837 user        3   1 root /bin/sh -c /bin/bash bash
4026532775 mnt         3   1 root /bin/sh -c /bin/bash bash
4026532776 uts         3   1 root /bin/sh -c /bin/bash bash
4026532777 ipc         4   1 root /bin/sh -c /bin/bash bash
4026532778 pid         4   1 root /bin/sh -c /bin/bash bash
4026532779 net         4   1 root /bin/sh -c /bin/bash bash
4026532891 cgroup      4   1 root /bin/sh -c /bin/bash bash
4026532892 user        1  11 root -sh
4026532893 mnt         1  11 root -sh
4026532894 uts         1  11 root -sh

What's the problem: I'm using docker with docker-compose, and currently i tried running unshare command in ENTRYPOINT section of my Dockerfile:

ENTRYPOINT /bin/bash && unshare -rum &

However, it seems to work, but won't let me enter the container for some reason. I've tried different variations, but still no luck

Is there a way to perform such a thing?

0

There are 0 best solutions below