Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error loading shared library libpq.so.5: No such file or directory #1

Open
botisma opened this issue Oct 6, 2017 · 3 comments
Open

Comments

@botisma
Copy link

botisma commented Oct 6, 2017

Looking to build a rust project with your image. You can find my docker file here:

FROM rust_builder as builder

ENV RUST_NIGHTLY_RELEASE_DATE=nightly-2017-10-03
ENV	PG_VERSION 9.6
ENV RUST_BACKTRACE 1
ENV PG_USER root
ENV PG_PASSWORD root

# FOR the diesel-cli
ENV DATABASE_URL=postgresql://root:root@localhost/builder

RUN apt-get update -qq && apt upgrade -qy && apt-get install -qy --no-install-recommends wget gnupg ca-certificates && \
    (wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc --no-check-certificate | apt-key add - ) && \
    echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' > /etc/apt/sources.list.d/postgresql.list && \
    apt-get update -qq && apt-get install -qy --no-install-recommends wget gnupg ca-certificates && \
    apt-get update -qq && \
    apt-get install -qy \
    postgresql-${PG_VERSION} postgresql-client-${PG_VERSION} postgresql-contrib-${PG_VERSION} pwgen sudo \
    curl file git build-essential openssh-client libssl-dev sudo ssh libpq-dev \
    libsqlite3-dev default-libmysqlclient-dev automake autoconf libtool pkg-config libpq5 \
    && \
    apt-get autoremove && \
    apt-get clean

RUN echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config && \
    sed -ri "s|#alias ll='ls -l'|alias ll='ls -lh'|" ~/.bashrc && \
    echo 'eval `ssh-agent -s`' >> ~/.bashrc && \
    echo "export SSH_AUTH_SOCK=/ssh-auth-sock" >> ~/.bashrc

VOLUME /home/rust/.rustup

WORKDIR /home/rust/src

RUN service postgresql restart && \
    service postgresql status && \
    sudo -u postgres createuser --superuser $PG_USER && \
    sudo -u postgres psql postgres -tAc "ALTER user $PG_USER with PASSWORD '$PG_PASSWORD'"

RUN rustup target add x86_64-unknown-linux-musl \
    --toolchain ${RUST_NIGHTLY_RELEASE_DATE}

COPY ./.ssh /home/rust/.ssh
COPY ./project/source/src /home/rust/src/src
COPY ./project/source/migrations /home/rust/src/migrations
COPY ./project/source/Cargo.* /home/rust/src/

RUN cd /home/rust/src/ && \
    cargo install diesel_cli --no-default-features --features "postgres"

RUN service postgresql restart && \ 
    cd /home/rust/src/ && \
    diesel setup && \
    eval "$(ssh-agent -s)" && \
    ssh-add /home/rust/.ssh/project && \
    ssh-add -l && \
    cargo build --release -vv --target=x86_64-unknown-linux-musl

FROM debian:stretch

ENV SSL_CERT_FILE /etc/ssl/certs/ca-certificates.crt
ENV SSL_CERT_DIR /etc/ssl/certs

RUN apt-get update -qq && \
    apt upgrade -qy && \
    apt-get install -qy --no-install-recommends ca-certificates musl \
    && \
    apt-get autoremove && \
    apt-get clean

COPY --from=builder /home/rust/src/target/x86_64-unknown-linux-musl/release/project_bin /project_bin

ENV HTTP_PORT 8080
ENV ROCKET_PORT=8080
ENV ROCKET_ADDRESS=0.0.0.0

EXPOSE $HTTP_PORT

ADD ./project/source/Rocket.toml /

RUN chmod +x /project_bin

# ENTRYPOINT ["./project_bin"]
ENTRYPOINT while : \ ; do date; sleep 1; done

But look the binary is not fully static.

root@d3b6c5e7acd4:/# ./project_bin
Error loading shared library libpq.so.5: No such file or directory (needed by ./project_bin)
Error relocating ./project_bin: PQstatus: symbol not found
Error relocating ./project_bin: PQresultStatus: symbol not found
Error relocating ./project_bin: PQntuples: symbol not found
Error relocating ./project_bin: PQgetisnull: symbol not found
Error relocating ./project_bin: PQresultErrorField: symbol not found
Error relocating ./project_bin: PQconnectdb: symbol not found
Error relocating ./project_bin: PQgetlength: symbol not found
Error relocating ./project_bin: PQexecPrepared: symbol not found
Error relocating ./project_bin: PQprepare: symbol not found
Error relocating ./project_bin: PQfinish: symbol not found
Error relocating ./project_bin: PQerrorMessage: symbol not found
Error relocating ./project_bin: PQgetvalue: symbol not found
Error relocating ./project_bin: PQcmdTuples: symbol not found
Error relocating ./project_bin: PQclear: symbol not found

Can find solution to fix it. Do you have an idea?

@botisma
Copy link
Author

botisma commented Oct 7, 2017

think i found it. It is something related to https://github.com/sgrif/pq-sys/pull/18/files?

@golddranks
Copy link
Owner

Oops, sorry, missed this. Yes, indeed. pq-sys won't link statically without that patch.

@golddranks
Copy link
Owner

Just for the record, the patch is on the newest pq-sys master, but that isn't released yet. Once it gets released, I'm closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants