The oracledb container runs well, but when I loginto container using: docker exec -it oracledb bash
and try to shutdown the oracle instance SQL>shutdown immediate
When Oracle instance shutdown, the container also stop running.
CharGPT tells me it is because the main process it was running has terminated.
Can I shutdown Oracle instance while keeping the container active?
OR
My goal is do SQL>start NOMOUNT after shutdown oracle instance, how can I achieve that goal?
Good morning,
a container is running as long as the main-process within this container is running. As soon as this process stops the container stops, too.
That is how Docker works and how it is different from a virtual machine (e.g. VMWare).
To start an image with a different command than the one specified during build-time you can simply append the wanted command at the end of your docker run-command as in the following short example where I start a bash using the php:8-3.fpm-image: docker run -it php:8.3-fpm bash
Just for curiosity: Why do you combine -d and -it? You want to run the container in background (-d) AND want to have an interactive terminal (-it) within the container?
If you want to run it in background AND want to run a command I would prefer to start the container without the -it and afterwards use docker exec -it <containername|containerid> <command> to run the <command> within the container (usually a shell for troubleshooting purpose).
Thank you for your answer. It helped me better understand Docker’s inner workings.
Regarding the -it option, I found that it’s not necessary for docker run—the command works fine without it.
However, my question still remains: in a running container, is there a way to keep the main process running until I choose to shut it down?
Containers are not VMs, they are just an isolation layer. If you shut down the main process in a container, the container will terminate.
The usual “hacks” to keep a container running is using a shell loop or sleep as main process. You can then usually use docker exec -it <c-id> sh to run something in container.