How to modify postgresql config file running inside docker

Dev Niklesh
2 min readJan 29, 2021

--

Docker is the modern way of running any service today but it can sometimes overwhelming particularly because of the extra-care needed to configure these pre-built images. Almost all images in Docker hub comes with some default configurations (which is good for getting started!). But we must also know how to change these default configurations to suit our needs.

As the title says!, in this article we are going to see how to modify postgreSQL configuration running inside a docker container.

If you are reading this article I’m assuming that you know basic docker commands and postgres commands.

Let’s jump into action.

Firstly, you need to locate the postgresql.conf file inside the docker container which is super easy. Open pgadmin4 and connect to your database. Then run,

SHOW config_file;

In my case, the path to config file was, var/lib/postgresql/data/postgresql.conf

1. Start postgeSQL inside the Docker container.

To do this, make sure that your postgres docker container is running.

$ sudo docker exec -it <container-id> /bin/bash// Replace "<container-id>" with postgres container id

This will open bash shell inside Docker container.

2. Edit the postgresql.conf file

Let’s say, we need to increase max_connections of postgres from 20 to 100.

bash-5.0# vi var/lib/postgresql/data/postgresql.conf/* Search for max_connections and change from 20 to 100 */

Now, exit the bash and container (bash-5.0# exit).

3. Restart Docker container

sudo docker restart <container-name>

That’s it. You have successfully configured PostgreSQL inside Docker container.

To Verify you change, connect to Database via pgadmin4 and run,

SHOW max_connections;max_connections 
-----------------
100
(1 row)

Give me a clap/love if this article helped you. This gives me motivation to keep posting awesome tips using Docker, Nginx. Also, comment below if you have any queries or facing issues. I’ll try to help.

Next article is Going to be HUGE and AWESOME :heart_eyes:

Spoilers :arrow_down:

How to host your website from your laptop

Here, we are going to use modern architectures like Docker, Nginx, Node.js and also connect it a Domain. I will try to make this to be a cool project for your weekend and wonderful learning experience.

--

--

Dev Niklesh

MEAN Stack Developer hoping to land on moon building my own Rocket!