Docker – Running Postgres Scripts inside Container

I have created a docker container for postgres using following link .Have few pre existing postgres scripts which i need to run it inside the container .

Docker Image link-
https://registry.hub.docker.com/_/postgres/

  • building oracle docker image on mac os x fails with “This system does not meet the minimum requirements for swap space.”
  • Expose a docker port on Mac Osx to other computer
  • Docker on Mac: No space left on device
  • Spring Boot with MongoDB on Docker
  • What Docker image size is considered 'too large'?
  • Deploy-time commands inside Docker on Elastic Beanstalk
  • Tried with following command still no luck

      ADD runsqlscripts.sh /root/runsqlscripts.sh
      CMD ["postgres" "/root/runsqlscripts.sh" ]
    

  • Regarding docker daemon to spawn containers in a custom CIDR block
  • debug spring-boot in docker
  • communication between containers in docker
  • nginx reverse proxy for docker service
  • linux mke2fs failed: there's no device named /dev/ram0 inside my docker image
  • Get log of a systemd/journald in a docker container to “docker logs”
  • 2 Solutions collect form web for “Docker – Running Postgres Scripts inside Container”

    See a previous answer of mine for the best way to do this.

    "correct" way to manage database schemas in docker

    The problem is that you can’t run scripts immediately with the Dockerfile because Postgres won’t be running when the commands are issued.

    They recommend you run scripts from the docker-entrypoint.sh script, which will look at the ./docker-entrypoint-initdb.d directory for scripts that should be run after Postgres has started.

    WORKDIR /workspace
    CMD ["postgres", "/root/runsqlscripts.sh" ]
    
    docker run -v /root:/workspace IMAGE_ID
    

    If you want to map a host directory to your container in a given path, you need to call -v /host:/container in your container creation. Dockerfile can map directory but to a random path like /dev/disk/by-uuid/af414ad8-9936-46cd-b074-528854656fcd.

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