-1

I have pulled a postgres image and created a docker container called pgdb , which has exited. Here is what the terminal returns after typing docker ps -all:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
e62fdb45c727        postgres            "docker-entrypoint.s…"   19 hours ago        Exited (1) 14 minutes ago                       pgdb

now I am trying to restart my container by typing docker exec -it pgdb bash, however I am getting the following error message: Error response from daemon: Container e62fdb45c727baf9ca9d7b55401f870b35959a10f356a401f058f2e693adc2fd is not running

I tried to attach the container like so:

random@random-142:~$ sudo docker start pgdb
pgdb
random@random-142:~$ sudo docker attach pgdb
You cannot attach to a stopped container, start it first

but it also didnt work. Does anyone know how I could go about solving this? I am really desperate.

EDIT

container logs

random@random-142:~$ sudo docker logs pgdb
Error: Database is uninitialized and superuser password is not specified.
       You must specify POSTGRES_PASSWORD to a non-empty value for the
       superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".

       You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
       connections without a password. This is *not* recommended.

       See PostgreSQL documentation about "trust":
       https://www.postgresql.org/docs/current/auth-trust.html
Error: Database is uninitialized and superuser password is not specified.
       You must specify POSTGRES_PASSWORD to a non-empty value for the
       superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".

       You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
       connections without a password. This is *not* recommended.

       See PostgreSQL documentation about "trust":
       https://www.postgresql.org/docs/current/auth-trust.html

2 Answers2

1

To restart the container you can use this command

docker start -ai "container_name"
0

The docker container logs itself are self-explanatory. You need to specify the database and superuser password.

Add the following arguments while running your Postgres docker container:

-e "POSTGRES_DB=YOUR_DB_NAME" -e "POSTGRES_PASSWORD=YOUR_PASSWORD"

Example:

docker run -itd -p 5432:5432 -e "POSTGRES_DB=testdb" -e "POSTGRES_PASSWORD=password" --name pgdb postgres

If you are not willing to add any password, then use "POSTGRES_HOST_AUTH_METHOD=trust". Example:

docker run -itd -p 5432:5432 -e "POSTGRES_DB=testdb" -e "POSTGRES_HOST_AUTH_METHOD=trust" --name pgdb postgres
Kapil Khandelwal
  • 1,096
  • 12
  • 19
  • but how can I do this since my container is not running? – Andromachiii Rozakiii Apr 16 '20 at 09:29
  • this logs are from when I created the container and it was still running, right? how could I run it again it order to make modifications there? – Andromachiii Rozakiii Apr 16 '20 at 09:31
  • You need to remove the existing pgdb container and create a new one. While creating the new docker container, add the options that I mentioned above in the answer. Also, Can you share the command you are using to run `pgdb` container? – Kapil Khandelwal Apr 16 '20 at 09:32
  • thanks for you answer I will try it now! but there is no way to start that container again, right? – Andromachiii Rozakiii Apr 16 '20 at 09:38
  • I am not aware of any approach to add pass ENV variable into a stopped docker container. – Kapil Khandelwal Apr 16 '20 at 10:03
  • You need to delete and recreate the container. This is extremely routine and there are a wide range of Docker parameters that can only be specified at `docker run` time. You probably should specify an appropriate `-v` option to cause the database data to be stored outside the container too. – David Maze Apr 16 '20 at 11:12