I am trying to transfer cloud data into a Postgres database from within a Docker container. I built the container using docker-compose
with the following Dockerfile snippet:
FROM postgres:14
...
RUN apt-get update \
&& pip3 install awscli
RUN aws --version
RUN apt-get -y install postgresql-plpython3-14
# symlinks for extension
RUN ln -s /usr/lib/postgresql/plpython3.so /usr/local/lib/postgresql/plpython3.so \
&& ln -s /usr/share/postgresql/extension/plpython3u.control /usr/local/share/postgresql/extension/plpython3u.control \
&& ln -s /usr/share/postgresql/extension/plpython3u--1.0.sql /usr/local/share/postgresql/extension/plpython3u--1.0.sql \
&& ln -s /usr/share/postgresql/extension/plpython3u--unpackaged--1.0.sql /usr/local/share/postgresql/extension/plpython3u--unpackaged--1.0.sql
...
I then run:
$ docker exec -it <container> psql -U postgres -W
and here's the psql:
postgres=# CREATE EXTENSION plpython3u;
ERROR:extension "plpython3u" already exists
postgres=# DROP EXTENSION plpython3u;
ERROR: extension "plpython3u" does not exist
Obviously something is not right, but I have no idea what it is.
I had to rebuild the container to add the symlinks and I used docker-compose build --no-cache
. I tried searching for similar issues, but all I've found are suggestions to add the symlinks, which I have already done.
Thanks.
CodePudding user response:
You're performing some unnecessary steps in your Dockerfile; you don't need to muck around with any of those symlinks. Postgres in the image is installed in /usr
, not in /usr/local
.
If I simplify the Dockerfile down to:
FROM postgres:14
RUN apt-get update && \
apt-get -y install \
postgresql-plpython3-14
And then build and run the image, I see:
$ docker run -d --rm -e POSTGRES_PASSWORD=secret --name pgtest pgtest
...
$ docker exec -it pgtest psql -U postgres
psql (14.6 (Debian 14.6-1.pgdg110 1))
Type "help" for help.
postgres=# create extension "plpython3u";
CREATE EXTENSION
postgres=# drop extension "plpython3u";
DROP EXTENSION