Where to COPY my app files, etc when jenkins pipeline docker container runtime settings are overriding my Dockerfile settings?

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Where to COPY my app files, etc when jenkins pipeline docker container runtime settings are overriding my Dockerfile settings?

Daniel Petersen
I'm trying to setup a pipeline where a container is built, run, and appropriate tests run in the container, all during the job. The challenge I'm hitting is that jenkins seems to be overriding my WORKDIR and USER that I specify in my Dockerfile. My Dockerfile looks like this:
FROM nodesource/nsolid:alpine

# Create `app` group and user since the base nodesource image
# doesn't currently.
RUN addgroup -g 1000 app \
    && adduser -G app -u 1000 -h /app -D app

USER app
ENV NODE_ENV=development
COPY package.json /app/package.json
COPY . /app
RUN npm install

In my pipeline I'm doing this:
testci_env = docker.build(testci_imageTag, '-f docker/Dockerfile.test .')
           testci_env.inside("--net=${network}") {
             try {
               sh 'npm run test-ci'
             } catch(err) {
               currentBuild.result = 'FAILED'
           }  //end testci_env.inside

In Jenkins output I'm seeing that it's building the image as I would expect, but then it's overriding the WORKDIR and USER settings I've specified in my Dockerfile when it runs 'docker run' to create a container:
docker run -t -d -u 233:233 --net=tmp_hrs_jenkins-sandbox-hrs_build_image_test1-66 -w /home/jenkins/workspace/sandbox/hrs_build_image_test1 --volumes-from c51d585c10d38a36ce98726508144026399c6d1b4cca590c87a3dd19cb73893d -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** --entrypoint cat tmp_hrs_testci_d5f106f-66

The issue as I see it is jenkins overriding a lot of my Dockerfile settings:
*my WORKDIR in Dockerfile will be overridden by jenkins during runtime
*The COPY directive in the Dockerfile isn't going to put my application files where Jenkins will later override the WORKDIR to point to
*jenkins is going to override the user to 'jenkins'

The result of course is my application tests can't run properly because the env isn't as specified in the Dockerfile.

I have tried passing in the relevant arguments -w and -u on the .inside line, just like I'm doing with the --net arg, but jenkins simply appends them to what it already thinks it should be doing, so I end up with my -w as well as jenkins -w, etc, which of course isn't helping.

It's possible I'm not approaching this in the way the docker functionality inside jenkins pipelines was intended to be used. How are folks working around the issues I'm hitting?

I've had a hard time finding detailed documentation that covers the docker.build and .inside methods in detail, as well as best practices for using them.


You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/2019dfca-c00e-4690-add0-3360f9a9618b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.