However, this also means I need to figure out regularly used tasks involving these new technologies. Adding Postgres and Docker to my toolbox has increased my effectiveness in my software business. This is especially the case when I paid to learn about cookiecutter-django. Starting in mid 2018, I moved towards using Postgres and Docker instead. MySQL for database and VirtualBox and Vagrant for running my environments. Title: "How to Restore Database Dumps for Postgres in Docker Container"īefore 2018, I largely use the following technologies. PGADMIN 4 FOR DOCKER SOFTWAREĭocker is a set of tools that utilises OS-level virtualization to running software in packages called container.How to Restore Database Dumps for Postgres in Docker Container By running a container for development environment, While Docker is mainly used in deployment, it can also be use in development environment. We can avoid to install a bunch of tools or languages on our machine.įor example, we can use Docker to run service such as postgres and pgadmin for database service and administration platform for PostgreSQL respectively in a container. To demonstrate, we will configure Postgres and pgAdmin with Docker Compose for database service for our development environment.įirst, we need to install the tools required.īoth can be installed by referring to the official guide on how to install based on our machine platform.ĭocker Compose is a tool for defining and running multi-container Docker applications. Stream the log output of running services.īy using Docker Compose, we can orchestrate on how the applications/services start in the container by a single command.Next, we are going to create a Docker Compose file docker-compose.yml to define the services that we are going to run in the container. pgadmin: Administration and development platform for PostgreSQL.Next, we are deploying and running the service by execute command: docker-compose up -d.įigure 02: Example docker-compose up -d output PGADMIN_LISTEN_PORT : 80 ports : - 15432 : 80 volumes : - pgadmin :/var/lib/pgadminįirst, we are going to check and validate the Compose file by execute command: docker-compose config.įigure 01: Example docker-compose config output Pgadmin : image : dpage/pgadmin4 : 4.23 environment : PGADMIN_DEFAULT_EMAIL : : password Volumes : - postgres :/var/lib/postgresql/data Version : "3" services : postgres : image : postgres :12.3 -alpineĮnvironment : POSTGRES_PASSWORD : postgres The output may vary depends on if we already downloaded the images and setup the volumes. To check if services are running successfully, we can use command: docker-compose ps.įigure 03: Example docker-compose ps outputĪfter running Docker Compose services, open web browser and go to localhost:15432. The port number is based on the mapping we configured under pgadmin service. Then key-in the email and password configured using the environment variable: PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD.Įnter Name under General. The value can be anything.Įnter Host name/address, Username and Password under Connection. For Host name/address, the value is the Docker Compose database service name, in our case is postgres.For Username, the value is the environment variable POSTGRES_USER.For Password, the value is the environment variable POSTGRES_PASSWORD.Īnd click Save to finish create.Compose file version 3 reference docker.: Updated the guide with a more up-to-date method for sending a password along with the commands.Why and How To Use Docker for Development.To stop Docker Compose service, just execute command: docker-compose downįigure 09: Example docker-compose down output After done, we can get access to the database from the sidebar. I ran into this just today, and thought I'd share one method that I felt was easy, fast and served my purpose. Depending on why you need to dump/restore a database, this might help for you, too. Since you are not able to provide a password directly through arguments, we rely on the PGPASSWORD environment variable: docker exec -i pg_container_name /bin/bash -c "PGPASSWORD=pg_password psql -username pg_username database_name" /desired/path/on/your/machine/dump.sql Restore using psql This quickie assumes you have nothing directly installed on your development machine, so everything is run straight from and to the Docker PostgreSQL container you're running. Note: If you are attempting to restore data from a custom format dump, you should instead use pg_restore as I described in my How to set up and use Postgres locally article. Note: By default PostgreSQL keeps importing even when errors occur. If you would instead prefer to stop the import completely upon error, be sure to add -set ON_ERROR_STOP=on to your above command.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |