1

I'm extending the postgres image with an argument POSTGRES_PASSWORD=postgres so that my derived container would already have a default password using docker build with dockerfile.

Whenever I ran psql -U postgres on the container from the derived image i made from postgres, I get:

could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

On my DockerFile I have:

ARG POSTGRES_PASSWORD=postgres
FROM postgres:alpine

RUN apk add --update nodejs
RUN apk add --update npm
RUN apk add --update erlang
RUN apk add --update elixir

CMD ["/bin/bash"]

then I ran

docker build -t myImage .
docker run --name sample -d -it myImage
docker exec -it sample bash

I want to run psql -U postgres on sample container (image extended from postgres).

3
  • This seems like you're looking for an orchestration system like Docker Compose, more than trying to fix these things in a Dockerfile. The CMD setting to run a shell instead of starting the database would be the immediate cause of your error. Commented Apr 14, 2019 at 13:53
  • @DavidMaze Making an image with elixir and postgres running is not possible? Should I use docker compose to connect postgres image and elixir image? Commented Apr 14, 2019 at 14:39
  • 1
    Yes, you should absolutely run your database and applications in separate containers. Commented Apr 14, 2019 at 15:32

1 Answer 1

2

Try to replace ARG POSTGRES_PASSWORD=postgres by ENV POSTGRES_PASSWORD postgres

The postgres docker image documentation state that this parameter is an Environement Variable, so this might help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.