docker Performs a command operation outside a container inside a container
- 2021-09-16 08:31:53
- OfStack
Sometimes we want to execute a command in a container, but we don't want to enter the container. So what should I do?
So the script can be written like this
#!/bin/bash
DOCKER_ID=62f3f40ab240
sudo docker exec -it $DOCKER_ID /bin/bash -c 'cd /packages/detectron && python tools/train.py'
done
Additional knowledge: Solve the problem of seamless call of shell commands between docker container and host
I won't talk too much, let's see the solution ~
nsenter -t 1 -m -u -n -i sh -c "echo hello world! "
(docker container plus privilege permissions, set pid: "host")