Is there a way to pass sqlhost name dynamically in Docketfile

12/8/2019

We have created a sqlhost file in gitrepo along with dockerfile, kubernetes yaml file and jenkinsfile,each time I have to manually add entry in sqlhost file which later dockerfile takes the value from sqlhost Is there a way from jenkins which can pass value as a parameter to dockefile and then build dockefile

-- Girish Reddy
docker
jenkins
kubernetes

2 Answers

12/9/2019

You can use an ARG or an ENV instruction to specify variables that are needed to be available to the Dockerfile

ARG: Sample dockerfile

FROM ubuntu
ARG SQLHOST 

Here you can see the SQLHOST Argument is provided in dockerfile, and while buiding specify as

$ docker build --build-arg SQLHOST=prod-vm.example.com .

also you can use specify same in Jenkins configuration.

ENV: Sample dockerfile

FROM ubuntu
ENV SQLHOST defaultHost

Here you can see the SQLHOST Environment variable is provided in dockerfile, and while buiding specify as

$ set SQLHOST=prod-vm.example.com; docker build .

also you can use specify same in Jenkins configuration.

-- Umesh Kumhar
Source: StackOverflow

12/8/2019

Did you try ARG? Please refer this documentation for more details.

-- Bimal
Source: StackOverflow