How to generate a Postgresql Dump from a Docker container?

前端 未结 5 605
忘掉有多难
忘掉有多难 2021-01-31 02:55

I would like to have a way to enter into the Postgresql container and get a data dump from it.

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-31 03:40

    Although the mountpoint solution above looked promising, the following is the only solution that worked for me after multiple iterations:

    docker run -it  -e PGPASSWORD=my_password postgres:alpine  pg_dump  -h hostname -U my_user my_db > backup.sql
    

    What was unique in my case: I have a password on the database that needs to be passed in; needed to pass in the tag (alpine); and finally the hosts version of the psql tools were different to the docker versions.

提交回复
热议问题