Home > Mobile >  Installing git overwrites curl library in Docker
Installing git overwrites curl library in Docker

Time:10-18

I'm trying to create a Docker image with git-ftp so I can deploy to an sftp server.

git-ftp requires git and curl compiled with libssh2, which is usually not included, so I found a Docker image from the curl devs which comes with sftp support:

% docker run --rm curlimages/curl:7.79.1 --version

curl 7.79.1-DEV (x86_64-pc-linux-musl) libcurl/7.79.1-DEV OpenSSL/1.1.1l zlib/1.2.11 brotli/1.0.9 libssh2/1.9.0 nghttp2/1.43.0
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher gophers http https imap imaps mqtt pop3 pop3s 
rtsp scp sftp smb smbs smtp smtps telnet tftp 
Features: alt-svc AsynchDNS brotli HSTS HTTP2 HTTPS-proxy IPv6 Largefile libz NTLM 
NTLM_WB SSL TLS-SRP UnixSockets

However, using it as the base image in my Dockerfile, after installing git I lose sftp support:

FROM curlimages/curl:7.79.1

USER root
RUN apk add --no-cache bash git
RUN git clone https://github.com/git-ftp/git-ftp.git

USER curl_user

WORKDIR /git-ftp

ENTRYPOINT ./git-ftp push --user $FTP_USER --passwd $FTP_PASSWORD $FTP_HOST
% docker run --env FTP_USER=user --env FTP_PASSWORD=password --env FTP_HOST=sftp://localhost:22 git-ftp
fatal: Protocol 'sftp' not supported by curl, exiting...

Running with ENTRYPOINT as curl --version gives me the following:

curl 7.79.1-DEV (x86_64-pc-linux-musl) libcurl/7.79.1 OpenSSL/1.1.1l zlib/1.2.11 brotli/1.0.9 nghttp2/1.43.0
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher gophers http https imap imaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: alt-svc AsynchDNS brotli HSTS HTTP2 HTTPS-proxy IPv6 Largefile libz NTLM 
NTLM_WB SSL TLS-SRP UnixSockets
WARNING: curl and libcurl versions do not match. Functionality may be affected.

So, suddenly, after installing git I lose sftp support, which is the only reason I'm using this base image.

What's going on? How can I fix this?

CodePudding user response:

Git requires libcurl for HTTP and HTTPS support. Because a Git without HTTPS support is not very useful, most distro packages of Git depend on the distro package of libcurl.

What is likely happening in your case is that when you install Git, its dependency, libcurl, is also being installed from the distro package. The custom libcurl is either installed in the normal location without a suitable package and is therefore being overwritten, or it's installed somewhere later in the library search path and is being ignored because the distro version is being preferred.

You should run ldd $(which curl) both before and after the installation of Git and find out where the custom and distro versions of libcurl are located. If the image is installing libcurl into somewhere under /usr/lib, then it's broken: that location is reserved for the package manager, and it would need to build and install a normal system package with its custom version to avoid being overwritten. Otherwise, you may be able to modify /etc/ld.so.conf to adjust the search path of the library, or use the LD_LIBRARY_PATH environment variable to do so on a per-program basis.

CodePudding user response:

My solution was to compile curl with libssh2 after installing git. Takes longer to build the image but it's lighter than using Debian.

  • Related