My goal is to start some services by executing the shell script in the container when starting the container, but I did
docker run -it --privileged=true newtest /bin/bash -c 'sh ./init.sh'
After the command, the container is in the existing state.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f14863acb5d7 newtest "/bin/bash -c init.sh" Less than a second ago Exited (127) 4 seconds ago serene_wing
Process No.1 in the container needs to be stopped. Your No.1 process is init.sh, and it will certainly survive after execution. If you write an infinite loop in init.sh, you will achieve the desired effect.