docker-oracle-xe-11g icon indicating copy to clipboard operation
docker-oracle-xe-11g copied to clipboard

init scripts to be executed only once

Open juanrferia opened this issue 7 years ago • 1 comments

Hi,

I have an automated exported SQL script I use to initialize the database. My expectation is this init script to be executed only once, for initialization purpose. Now they are executed every time I start the container.

As a reference, please have a look to official MySQL docker image to see how it only executes the init scripts if the database is not initialized:

https://github.com/docker-library/mysql/blob/master/8.0/docker-entrypoint.sh

You can see: if [ ! -d "$DATADIR/mysql" ]; then ... for f in /docker-entrypoint-initdb.d/*; do case "$f" in *.sh) echo "$0: running $f"; . "$f" ;; *.sql) echo "$0: running $f"; "${mysql[@]}" < "$f"; echo ;; *.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;; *) echo "$0: ignoring $f" ;; esac echo done ... fi

juanrferia avatar Jun 18 '17 15:06 juanrferia

Well, as I understand, after playing with Docker a few days, the instructions, described in the Dockerfile, actually, executed only once. More specific, when you build your image. After building the image, when you run it (creating a container's instance), none of the Dockerfile's commands are executed. Actually, the commands, executed while building the image, make some changes to the image, and never recalled again. It's very similar to OS installation process (for ex., from ISO image): every script or command or instruction, written down on the ISO image, are expected to make some changes on the installing process. After you finish the installation, and every time you boot this OS, you can make additional changes, but these will not be reflected in the ISO image (Dockerfile). So, if you need some instruction to be executed only once - just put it in the Dockerfile and it will be executed on the building stage.

efibutov avatar Dec 25 '18 23:12 efibutov