Reputation: 1628
I started a container instance using a postgres image. Whilst the container was running I connected to it using
docker exec -it postgres-13.1 bash
From here I edited the postgresql.conf
and introduced a typo such that attempting to restart the container immediately exits and the logs show
FATAL: configuration file "/var/lib/postgresql/data/postgresql.conf" contains errors
It isn't possible to excute a bash script using docker exec -it postgres-13.1 bash
because this only applies to a running container.
What command can I issue to start the container and drop directly into a bash shell instead of attempting to start the database server?
Upvotes: 0
Views: 324
Reputation: 111
Regarding good solution by Chris, the more stable solution is to mount postgresql.conf
file onto your host machine. Doing so, you'll be able to change your postgre configurations without accessing to running container. You also won't need to docker cp conf file into the container. you can mount .conf file as below
docker run -v /home/<your-user>:/var/lib/postgresql/data/postgresql.conf ....
But if you've created the container in prior, you now should change the container configurations via /var/lib/docker/containers/<postgre-container-long-hashed-ID>/hostconfig.json
file:
1. docker stop <postgre-container>
2. change /var/lib/docker/containers/<postgre-container-long-hashed-ID>/hostconfig.json file as formal notation for mounting a filesystem
3. save changes to hostconfig.json file
4. sudo systemctl start docker.service
5. docker start <postgre-container>
Upvotes: 0
Reputation: 817
As Chris Mentioned, docker cp
command works for your case
Create a file (say correct-postgresql.conf ) with configuration in your machine and do the following and then you can start your container and it works fine.
docker cp correct-postgresql.conf <containerId>:/var/lib/postgresql/data/postgresql.conf
Upvotes: 0
Reputation: 36016
docker cp
can copy files into (or out) a stopped container.
This should be sufficient to repair the file and restart the container.
Upvotes: 3