Search code examples
dockercurldockerfilepassword-protection

How to hide user and pass in curl command in dockerfile


I Have a dockerfile and in one of last steps, I download a WAR file from artifactory, so I can use it in the containers in the webapps/ directory.

Thing is I don´t want to show user and pass of curl -u command. How can I hide both users and password in following command? Is there a way in docker to hide/encrypt passwords?

RUN curl -u user:pass -O "https://artifactory.xxxx.com:443/artifactory/api/api-0.0.1-SNAPSHOT.war"

Solution

  • You can use multi stage build to achieve a lightweight image, but you have to use one single docker build, instead of two. Like this single Dockerfile:

    FROM maven as build
    (... Your app build....)
    FROM tomcat
    COPY --from=build artifact.war /dest/dir
    

    Everything before the second FROM is discarded from the resulting image, so it will contain Tomcat, not Maven, and your copied artifact.