I have no experience with postgresql, but from a dockers point of view, this approach seems perfectly fine. Your data will be in the data container. docker-compose build && docker-compose up will not affect it. Raman Gupta gives a good introduction to this topic in his article.
In this, he also emphasizes that you need the right mindset for data-only containers. For you, this means that you may have a "backup container". Use the postgres image and start a new container from it, which uses --volumes-from myweb_data_1 . Now in the container you have the appropriate tools from postgresql and access to your database in the data container.
Again, postgresql may be different, but for mysql it is a way that works fine and works best for me. By the way, mysql is a server. So you have to start a new container and bind it ( --link ) with the container myweb_db_1 . Not sure how postgresql works.
source share