Docker privileged containers

Hello, we have a ubuntu 18.04 host on which we are running docker container. We want the container to have root privilege on the host so we are running the container with privileged option. Now if I want to run a bash script on the host from the container how do i do it? let’s say the bash script will have a simple command to reboot the host machine. how do i execute that from within the container?

Hi

Im not sure you can execute commands ON the host (like reboot), but it is possible to get information or write files on the host.

docker run -ti --rm --privileged --net=host --pid=host --ipc=host busybox top

Will give you output from the top command, from the host.
If you want to mount the fs, you can use " -v /:/host " and your host fs will be accessible via the container also.

Thanks @terpz , to give you the full context we are using IoT Edge containers. So running docker run command is not really in our control but we can use container create options if we want to. (ref: Docker Engine API v1.30 Reference). This is how we pass the --privileged option.

Is there any way that once the container is created, we can run commands from within the container?