Initialize docker volume ony once

I would like to initialize a docker volume only after it has been created, not each time a container is created or built.

For example lets say I want to store the content of a database in the volume. At the creation of the volume I would like to create the database schema, but once this schema exists I don’t want to create it again since it could cause some unwanted side effects.

  • Docker. Exec npm command in different folder
  • CMake autogenerated Makefile on ubuntu 16.04 docker image prepending “//” to targets
  • Building meta-virtualization layer in yocto
  • Docker container on Marathon doesn't finish
  • Run Jenkins Job in a container
  • What's the diff between Empty and No Value for Docker Volumes From?
  • Right now one of the solution I see is to create a flag in the volume once it has been initialized and in later calls check if this flag exists before performing the initialization.

    I just wanted to know if docker has a native way of achieving it.

  • Bundle install failes on docker
  • Flask API breaks at long Cypher query
  • Can't run docker commands
  • Docker run rabbitmq -e RABBITMQ_SSL_CERT=/path/to/cert/file
  • Nginx SSL inside a docker container
  • Docker-Compose Persistent Data Trouble
  • One Solution collect form web for “Initialize docker volume ony once”

    Create your own custom image that gets built with database schema created with database’s data directory stored into a docker volume. Later on use that image to create/run containers.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.