Execute script in Dockerfile

Hello,

I am trying to run provisioning .sh script for sonatype/nexus3 image:
https://hub.docker.com/r/sonatype/nexus3/tags/

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.

Should I override nexus3 image Dockerfile?

Thanks for help :slight_smile:

You’re probably looking for the RUN command, not CMD

Is it RUN used only in image build phase not container running?

RUN is only for Dockerfile :slight_smile:

For telling the Dockerfile which command to run when the container start, see “ENTRYPOINT” and “CMD”

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 :slight_smile: Is it possible to have both: working container and executed script?

then in your provisioning script, you need to put the command of the proccess you want to be running

Is it possible to retrieve parent image process code and - using it - extend my CMD process?

It is… but it is not the way you should do it.

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.