How to execute shell scripts in a container when docker starts a container

my goal is to execute the shell script in the container to start some services when starting the container, but after executing

    docker run -it --privileged=true newtest /bin/bash -c "sh ./init.sh" 
After the

command, the container is the state of the Exited.

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
Mar.19,2021

process No.1 in the container cannot be stopped if needed. Your No.1 process is init.sh, of course, it will stand up after it has been executed. You write an infinite loop in init.sh and you get the effect you want.

Menu