-3

I am newly using Docker and venvs for a new Django Project. I am trying to run my server, however, I got an issue that bash: psql: command not found So, I followed a few different Stack Overflow suggestions, like this Postgresql -bash: psql: command not found, but I actually screwed up my situation even more. After changing the path to the path to my postgres, now not only is psql commands not recognized, but neither is python or anything else.

I'm new to virutal environments and docker, so I'm pretty lost here. Any suggestions?

Andrew Bregman
  • 190
  • 1
  • 17

1 Answers1

0

I suggest that you "shell into" your docker image and take a look around. Figure out where your psql is installed and look at the value of your PATH environment variable. Here's the command to "shell into" your docker image:

docker run -it --entrypoint sh <image-name>

The image names are found in your docker environment with this command:

docker images 

I know I had some trouble with python and psql (that I solved with a posting at SO). Here's the Dockerfile that I wound up with:

$ cat Dockerfile 
FROM python:3.6-alpine as base
  
FROM base as builder
RUN mkdir /install
RUN apk update && apk add postgresql-dev gcc python3-dev musl-dev
WORKDIR /install
COPY requirements.txt /requirements.txt
RUN pip install --prefix=/install -r /requirements.txt

FROM base
COPY --from=builder /install /usr/local
ENV PATH="/app:${PATH}"
RUN apk --no-cache add libpq
COPY src /app
WORKDIR /app
ENTRYPOINT [ "myapp" ] 


$ cat requirements.txt 
click
requests
configparser
psycopg2
flask

I think that the only package you need from my requirements.txt file is psycopg2. Also, you'll clearly need to make some changes to include your dependencies and specify your entrypoint (rather than "myapp").

You may be able to completely ignore my entire posting and just focus on this aspect:

ENV PATH="/app:${PATH}"

The PATH tells the execution environment where to find your executables. The problem that you are seeing is that bash cannot find psql - so update your PATH to wherever psql is installed in your image. If you don't know the path to psql in your image, you might find it by run'ing your image (with the modified entrypoint as shown abouve) and just doing a find from the root.

Or you can combine the commands as follows:

docker run -it --entrypoint sh <image-name> -c "find / -name psql "

Or you can even just make find your entrypoint:

docker run -it --entrypoint find <image-name>  / -name psql
Mark
  • 4,249
  • 1
  • 18
  • 27
  • (If you specify the main container command using `CMD` rather than `ENTRYPOINT`, you can use a more natural `docker run --rm image-name find / -name psql` syntax, without the `--entrypoint` option and without awkwardly needing to split the command.) – David Maze Aug 22 '21 at 21:22
  • @DavidMaze @Mark Trying to follow other stack overflows, I screwed it up even more so that when I type `docker images` it returns that `bash: docker: command not found` – Andrew Bregman Aug 22 '21 at 21:59
  • It looks like your host's PATH is also messed up (or you don't have docker installed). Start another terminal session to get your PATH back to normal (or edit your profile). Your bash profile is here: ~/.bash_profile . – Mark Aug 23 '21 at 00:04