![]() At the terminal type: docker container run -d -name=pg -p 5432:5432 -e POSTGRES_PASSWORD=docker -e PGDATA=/pgdata -v /pgdata:/pgdata postgres.Get a PostGreSQL database running in a container.Here is my effort to get a database up and running in a container and then connect to said database with Dbeaver and then QGIS.ĭbeaver Community Edition Download and install After some internet work I found some handy sources for running databases in containers and so I thought I would try it out as a platform for learning more. Recently I was reminded about Docker, which I have used to spin up Rstudio instances before. Since then I really haven’t had data that would warrant the effort needed to design and setup a database. I like it when things make my life easier.I’ve been wanting to explore more possibilities in databases and spatial data since working on a large data project during my PhD. Just fire it up, set host as localhost, or the default local IP and port, enter “postgres” as user and password, the name of a database you created, and test it out.ĭevelopment is tough enough as it is. Now, if you're a GUI kind of person, you may be asking, “yeah but can I still connect to my database using TablePlus?” Happily the answer is yes. Then run psql and this SQL command to set your password ALTER ROLE postgres WITH PASSWORD 'postgres' To do this, get the container id running “docker ps -a” then exec into the container docker exec -it bash If you are unable to login with psql and you get an error like psql: error: FATAL: role “root” does not exist, you may need to set the Postgres user password manually from within the running container. ![]() Now you should be able to connect with psqlĮnter your password “postgres” and you should see something like this psql (13.2) Obviously don't do that in prod, you're not silly. You can set POSTGRES_USER and POSTGRES_PASSWORD to whatever you want, but “postgres” makes it simple for local dev. v $HOME/docker/volumes/postgres:/var/lib/postgresql/data postgres ![]() Something like mkdir -p $HOME/docker/10.17/volumes/postgresįire up the Postgres container adding the volume flag to your newly created directory docker run -rm -name pg-docker \ If you install multiple versions for various projects/environments, I find it useful for cleanup if you set the persistent volume directory to be version specific. Now make a directory for your persistent volume to store the database on your machine mkdir -p $HOME/docker/volumes/postgres Or a specific version to match your deployment env docker pull postgres: Now grab the latest version of the Postgres container docker pull postgres ![]() Next, create a symlink for psql (you could also add it to your path instead if you prefer) ln -s /usr/local/Cellar/libpq/13.2/bin/psql /usr/local/bin/psql brew install libpqĬheck the version to verify it worked ls /usr/local/Cellar/libpq Install it by running this command in your terminal. One quick thing to note is on a Mac (especially if you haven't installed Postgres manually on your machine), you will need libpq to give you the wonderful psql tool. I use Docker Desktop, it's nice, but I'm more into the CLI, and LazyDocker too which is cool. If you don't have that, you're probably reading the wrong article. Running Postgres from a docker container, not installing with Brew or gives you that beauty, and also lets you turn it off when you don't need it, saving your battery. Installing Postgres directly on your machine is fine, but having the flexibility to quickly switch between the version you are running for development is beautiful. I'll keep this fairly succinct as there's really not much more to blab about than what's in the title.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |