Postgres: How to populate a bind-mounted volume?

Created on 24 Jul 2019  路  3Comments  路  Source: docker-library/postgres

I have one question. How to add custom dictionary for full text search to container. I mounted folder host to folder container (/usr/share/postgresql/11/tsearch_data) but folder host is empty.

Please help for me.

question

Most helpful comment

This is one of the nuances of Docker, you'll have to use one of several workarounds to populate a host-mounted volume with already existing data in the container. Using a docker-named volume will work as expected however.
https://github.com/moby/moby/issues/4361#issuecomment-351866126

bind mounting a host directory . . . it will not copy the content from the container to the host (even if the path on the host is empty).


A workaround to populate a folder, then you can just mount it pre-populated

$ docker run --rm postgres tar -cC /usr/share/postgresql/11/tsearch_data/ . | tar -xC ./folder

$ ls folder/
danish.stop   hungarian.stop              ispell_sample.affix  spanish.stop          usr/
dutch.stop    hunspell_sample.affix       ispell_sample.dict   swedish.stop          xsyn_sample.rules
english.stop  hunspell_sample_long.affix  italian.stop         synonym_sample.syn
finnish.stop  hunspell_sample_long.dict   norwegian.stop       thesaurus_sample.ths
french.stop   hunspell_sample_num.affix   portuguese.stop      turkish.stop
german.stop   hunspell_sample_num.dict    russian.stop         unaccent.rules

All 3 comments

This is one of the nuances of Docker, you'll have to use one of several workarounds to populate a host-mounted volume with already existing data in the container. Using a docker-named volume will work as expected however.
https://github.com/moby/moby/issues/4361#issuecomment-351866126

bind mounting a host directory . . . it will not copy the content from the container to the host (even if the path on the host is empty).


A workaround to populate a folder, then you can just mount it pre-populated

$ docker run --rm postgres tar -cC /usr/share/postgresql/11/tsearch_data/ . | tar -xC ./folder

$ ls folder/
danish.stop   hungarian.stop              ispell_sample.affix  spanish.stop          usr/
dutch.stop    hunspell_sample.affix       ispell_sample.dict   swedish.stop          xsyn_sample.rules
english.stop  hunspell_sample_long.affix  italian.stop         synonym_sample.syn
finnish.stop  hunspell_sample_long.dict   norwegian.stop       thesaurus_sample.ths
french.stop   hunspell_sample_num.affix   portuguese.stop      turkish.stop
german.stop   hunspell_sample_num.dict    russian.stop         unaccent.rules

Going to close since this isn't an issue with the image and there's nothing we can do to alleviate this

If you have further questions you could also try asking over at the Docker Community Forums, Docker Community Slack, or Stack Overflow

Maybe, this is how work internal of Docker. Thanks @wglambert

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jiffingomez picture jiffingomez  路  4Comments

AndriiOmelianenko picture AndriiOmelianenko  路  4Comments

harrybvp picture harrybvp  路  4Comments

tjamet picture tjamet  路  4Comments

weeger picture weeger  路  4Comments