Docker Compose pre or post scripts after container start

I searched the web and also docker compose file reference for a way to run a script(s) prior to a container build. I need this so I can update my docker build directory with latest artifacts for a service.I have a use case to run some post update script(s) to update the container after it was run as well. I currently can do all of this with bash wrapper scripts with docker commands. Wondering whether I can use docker-compose to do a pre/post script runs without resorting to wrapper bash shell type situation.

Environment:
docker-compose version: 1.7.1
docker version 1.12.0
OS: CentOS Linux release 7.2.1511

Please let me know if there are options or other approaches to do accomplish this. Thanks

1 Like

I’m not aware of a general convention or standard tooling for this. My Dockerfiles tend to have a setup.sh script alongside them.

The ENTRYPOINT script in a Dockerfile gets run whenever the container is started.

Thank you David. I am trying to run an Oracle container.

One of the steps is to change the default password and also I want to import a local database - all part of the run or docker-compose up -d.

Oracle has to be instantiated prior to a user logging and changing the sys passwords. My question is whether there are any mechanisms to do this in docker-compose like a hook after the container has started.

In the above example, the CMD calls ‘runOracle.sh’. I want to:

  • change the default passwords (run setPasswords.sh)
  • load a db (some load bash script…)

I can do the above using ‘docker exec’ easily and it works but it would be nice if I can integrate that as part of docker-compose or even docker build (via Dockerfile or scripts during run) and not as a separate script if possible.

I don’t know whether I am making it clear.

Thx.

2 Likes