This script can only be run when container is up & running. Is it possible to execute this script in Dockerfile? I was trying to run it via CMD command but after script was executed the container Exited.
So I should use CMD. Now lets assume that my Dockerfile contains: CMD ["./provisioning.sh"] after run my nexus container this script will be executed and container will stop but I want to be working Is it possible to have both: working container and executed script?
The best way to do that is to write an ENTRYPOINT script in your Dockerfile that does whatever setup is needed, and then ends with exec "$@" to run the normal CMD (or whatever got passed on the command line). The official mysql image entrypoint script 1.0k is a little bit complex, but it has the right basic pattern.
Following this pattern, you should be able to create an extension of the sonatype/nexus3 image and in your Dockerfile add the ENTRYPOINT script with your provisioning.
If you, however, need to have Nexus running, for example to add users, you need to override the start-nexus-repository-manager.sh script and add a reference to your provisioning script.