Dockerfile
for my NodeJS application looks like the following
FROM node:14-alpine AS build
# Install necessary packages using the 'apk' package manager
RUN apk update &&
apk add --no-cache wget build-base openssl-dev
# Install a more recent version of curl
RUN apk add --no-cache curl
# Set the source folder
ARG SOURCE_FOLDER="./"
ARG BUILD_VERSION
ARG NPM_TOKEN
# Create app directory
WORKDIR /var/www/app
# Bundle app source
COPY ${SOURCE_FOLDER} .
# Run the build.sh script
RUN chmod +x build.sh && ./build.sh
RUN NODE_OPTIONS=--max_old_space_size=4096 lsc build site --output-hashing all --buildVersion=$BUILD_VERSION &&
rm -f .npmrc
FROM app-base/docker-base
COPY --from=build /var/www/app/dist/ngx-rsc-app /var/www/app
I am trying to install latest version of curl and libcurl using the command
RUN apk add --no-cache curl
But when I go into my container and check the curl version
root@my-app:/var/www/app# curl --version
curl 7.74.0 (x86_64-pc-linux-gnu) libcurl/7.74.0 OpenSSL/1.1.1n zlib/1.2.11 brotli/1.0.9 libidn2/2.3.0 libpsl/0.21.0 (+libidn2/2.3.0) libssh2/1.9.0 nghttp2/1.43.0 librtmp/2.3
Release-Date: 2020-12-09
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps mqtt pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli GSS-API HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets
It shows curl 7.74.0
instead of curl 8.4.0
. How should I upgrade the curl and libcurl to the latest version 8.4.0
?
2
Answers
You’re using a multistage Dockerfile and installing
curl
in the first stage. That install doesn’t carry over to the final stage.There are (at least) 2 ways to update
curl
in the final imagecurl
in theapp-base/docker-base
image. That willupdate curl for all users of the base image.
curl
8.4.0 in the final stage of your Dockerfile. How to do that depends on what package manager is available in the
app-base/docker-base
image.
To upgrade
curl
andlibcurl
to the latest version in your Dockerfile, there are a few options:As mentioned, you can update
curl
andlibcurl
in theapp-base/docker-base
image that you’re using as your final stage. This has the benefit of upgrading all images that use that base, but requires updating the base image.You can install the latest
curl
andlibcurl
in the final stage of your Dockerfile. This will only upgrade that specific image.Since you’re using Alpine Linux, you can run:
This will install the latest available versions from the Alpine repos.
You can pull directly from the official
curl
Docker image to get the latest version:This ensures you always have the absolute latest
curl
andlibcurl
.As a last resort, you can install
curl
andlibcurl
from source to get a specific version. This is more complex but gives you full control.