wnameless / docker-oracle-xe-11g

Dockerfile of Oracle Database Express Edition 11g Release 2
Apache License 2.0
1.35k stars 801 forks source link

init scripts to be executed only once #56

Open juanrferia opened 7 years ago

juanrferia commented 7 years ago

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

efibutov commented 5 years ago

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.