I'm trying to build a docker image for jenkins that automates the configuration of the server. I'd like to use yaml for my config files. For that I need to make snakeyaml available to the groovy grapes. Here is my docker file
FROM jenkins/jenkins:2.107.3
ENV JAVA_OPTS="-Djenkins.install.runSetupWizard=false"
USER root
RUN mkdir -p /var/jenkins_home/files
RUN mkdir -p /var/jenkins_home/.groovy/grapes/org.yaml/snakeyaml/jars
RUN chown -R jenkins:jenkins /var/jenkins_home/files
RUN chown -R jenkins:jenkins /var/jenkins_home/.groovy/grapes/org.yaml/snakeyaml/jars
USER jenkins
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/ref/plugins.txt
COPY 03security.groovy /usr/share/jenkins/ref/init.groovy.d/03security.groovy
COPY ivy-1.21.xml /var/jenkins_home/.groovy/grapes/org.yaml/snakeyaml/ivy-1.21.xml
COPY snakeyaml-1.21.jar /var/jenkins_home/.groovy/grapes/org.yaml/snakeyaml/jars/snakeyaml-1.21.jar
COPY mainConfig.yml /var/jenkins_home/files/mainConfig.yml
COPY 03mainConfig.groovy /usr/share/jenkins/ref/init.groovy.d/03mainConfig.groovy
I don't why I'm having this problem, but when I run the build I'm getting this error:
chown: cannot access '/var/jenkins_home/files': No such file or directory
I've run similar commands in other images and not had this issue, but it won't let me create or access that file and I get the same error when I exclude it and try with only the .groovy/grapes path.
Any help in this is appreciated. Also, if you know a working solution to get snakeyaml(or another library) loaded into a jenkins docker image then I'd like to see that too.
I guess it's because /var/jenkins_home/ is volume. If you run command docker history jenkins/jenkins you will see it.
<missing> 2 months ago /bin/sh -c #(nop) VOLUME [/var/jenkins_home] 0B
You can add your files you want to copy to /var/jenkins_home, to direcotry /usr/share/jenkins/ref
COPY *.xml /usr/share/jenkins/ref/
It means that all you xml files will be copied into /var/jenkins_home after container starts.
Related
RUN adduser -D appUser
RUN mkdir /usr/share/app
RUN mkdir /logs
ADD Function/target/foo.jar /usr/share/app
WORKDIR /usr/share/app
RUN chown -R appUser /usr/share/app
RUN chown -R appUser /logs
USER appUser
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "foo.jar"]`
I've got this weird issue I can't seem to work my head around.
My root folder contains two directories, (both with subdirectories) 'Demo/Dockerfile' and 'Function/target/foo.jar'
I have a copy command in my Dockerfile that reads
COPY Function/target/foo.bar /usr/share/app
but when I run docker build -f Demo/Dockerfile from the root folder, I get an error
stat /var/lib/docker/tmp/docker-builder238823934/Function/target/foo.jar: no such file or directory
I find this a bit strange because when I edit the copy command to read COPY /target/foo.bar /usr/share/app and then I cd into the Function directory and run
docker build -f ../Demo/Dockerfile
it builds successfully, or if I edit the Dockerfile to read COPY foo.bar /usr/share/app and then cd into the target directory and run docker build -f ../../Demo/Dockerfile, this also works.
Is there an explanation for this sort of behavior?
This is what my dockerignore file looks like
!**/Dockerfile
!DockerServiceDescription/**
!Function/target/*.war
!server.xml
!tomcat-users.xml
Docker uses context directory and children only and does not allow using any files outside for security reasons.
You should show context directory to docker using '.' or so:
cd myproject
docker build -f Demo/Dockerfile .
I get an error when using the COPY --from=reference in my Dockerfile. I created a minimal example:
FROM alpine AS build
FROM scratch
COPY --from=build / /
This causes the following build output:
$ docker build .
Sending build context to Docker daemon 2.048kB
Step 1/3 : FROM alpine AS build
---> b7b28af77ffe
Step 2/3 : FROM scratch
--->
Step 3/3 : COPY --from=build / /
failed to copy files: failed to copy directory: Error processing tar file(exit status 1): Container ID 165578 cannot be mapped to a host ID
The builds run fine in CI, but it fails on my laptop running Ubuntu 18:04. What could be causing this issue?
I've just had this issue. I wanted to copy the binaries of a standard node image to my image in a multi-stage build.
Worked fine locally. Didn't work in BitBucket Pipeline.
As mentioned by #BMitch, the issue was use of userns.
With BitBucket, the userns setting is 100000:65536, which (as I understand it) means that the "safe" userIDs must be between 100000 and 165536.
The userID you have on your source files is outside of that range, but it doesn't mean it is userID 165578. Don't ask me why, but the userID is actually 165536 lower than the value reported, so 165578 - 100000 - 65536 = 42.
The solution I have is to change the user:group ownership for the source files to root:root, copy them to my image, and set the user:group ownership back (though as I'm typing this, I've not done that bit yet as I'm not 100% it is necessary).
ARG NODE_VERSION
FROM node:${NODE_VERSION}-stretch as node
# To get the files copied to the destination image in BitBucket, we need
# to set the files owner to root as BitBucket uses userns of 100000:65536.
RUN \
chown root:root -R /usr/local/bin && \
chown root:root -R /usr/local/lib/node_modules && \
chown root:root -R /opt
FROM .... # my image has a load of other things in it.
# Add node - you could also add --chown=<user>:<group> to the COPY commands if you want
COPY --from=node /usr/local/bin /usr/local/bin
COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
COPY --from=node /opt /opt
That error is indicating that you have enabled userns on your Ubuntu docker host, but that there is no mapping for uid 165578. These mappings should be controlled by /etc/subuid.
Docker's userns documentation contains more examples of configuring this file.
You can also modify the source image, finding any files owned by 165578 and changing them to be within your expected range.
I am trying to add a directory to my docker image. I tried the below methods. During the build I dont see any errors, but once I run the container ( I am using docker-compose) and get into it docker exec -it 410e434a7304 /bin/sh I dont see the directory in the path I am copying it into nor do I see it as a volume when I do docker inspect.
Approach 1 : Classic mkdir
# Define working directory
WORKDIR /root
RUN cd /var \
mdkir www \\ no www directory created
COPY <fileDirectory> /var/www/<fileDirectory>
Approach 2 : Volume
FROM openjdk:8u171 as build
# Define working directory
WORKDIR /root
VOLUME["/var/www"]
COPY <fileDirectory> /var/www/<fileDirectory>
Your first approach is correct in principle, only that your RUN statement is faulty. Try:
RUN cd /var && mkdir www
Also, please note the fundamental difference between RUN mkdir and VOLUME: the former simply creates a directory on your container, while the latter is chiefly intended for mounting directories from your container to the host your container is running on.
This is how I made it work:
# Define working directory
WORKDIR /root
COPY <fileDirectory> /root/<fileDirectory>
RUN cd /var && mkdir www && cp -R /root/<fileDirectory> /var/www
RUN rm -rf /root/email-media
I had to copy the from my host machine to docker image's working directory /root and from /root to the desired destination. Later removed the directory from/root`
Not sure if thats the cleanest way, if I followed the approach 1 with the right syntax suggested by #Fritz it could never find the the path created and throw an error.
After running the RUN layer it would remove the container (as below) and in the COPY line it would not have the reference to the path created in the run line.
Step 16/22 : RUN cd /var && mkdir www && cp -R /root/<fileDirectory> /var/www
---> Running in a9c7df27116e
Removing intermediate container a9c7df27116e
I have several files in a directory on the host machine which I am trying to copy to the container and also have some run commands inside my docker-compose.
The first set up until the crowd section stats woks fine, but anything from the crown jar down just fails and doesn't work. I tried to run the manial docker cp command to copy the files from host to the container and that works. Can someone please shed some light on this?
This is a part of my Dockerfile:
WORKDIR /usr/local/tomcat
USER root
COPY server.xml conf/server.xml
RUN chmod 660 conf/server.xml
USER root
ADD tomcat.keystore /usr/local/tomcat/
RUN chmod 644 tomcat.keystore
RUN chown root:staff /usr/local/tomcat/tomcat.keystore
ADD crowd-auth-filter-1.0.0.jar /usr/local/tomcat/webapps/guacamole/WEB-INF/lib/
ADD crowd-filter.properties /usr/local/tomcat/webapps/guacamole/WEB-INF/lib/
RUN chmod 644 crowd-filter.properties
ADD web.xml /usr/local/tomcat/webapps/guacamole/WEB-INF/
RUN /usr/local/tomcat/bin/shutdown.sh
RUN /usr/local/tomcat/bin/startup.sh
Thanks
I have created a very basic Dockerfile which wraps the official Jenkins Docker image. I am running an instance of my image and have come across the following problem:
I start and instance of my image and create a file in my instance in the /tmp directory(any directory will work) called tmp.txt.
I go to the "Script Console" of my running Jenkins instance and in the console, I type in the following code:
f = new File('/tmp/')
println f.list()
I expect to see a list of files including my newly created /tmp/tmp.txt but that file is not in the list. This is symbolic of the problem that is blocking me which is that I want to call evaluate() on a groovy script from a Jenkinsfile but that file is not script is not visible to Jenkins.
My gut feeling is that this has something to do with Docker file system layers. Something about the fact that since Jenkins is installed at a lower docker file system layer in the base image, it cannot access files created within the running instance layer above it. The behavior seems very weird but somewhat understandable.
Has anyone encountered this issue before? If so, how were you able to resolve it?
FROM jenkins
ENV JAVA_OPTS="-Xmx8192m"
USER root
RUN mkdir /var/log/jenkins
RUN chown -R jenkins:jenkins /var/log/jenkins
RUN mkdir /var/cache/jenkins
RUN chown -R jenkins:jenkins /var/cache/jenkins
RUN useradd -ms /bin/bash jenkadm
USER jenkadm
WORKDIR /home/jenkadm
COPY id_rsa /home/jenkadm/.ssh/
COPY id_rsa.pub /home/jenkadm/.ssh/
USER root
RUN mkdir -p /opt/staples/ci-tools
RUN chown jenkadm:jenkadm /opt/staples/*
USER jenkins
ENV JENKINS_OPTS="--handlerCountMax=300 --logfile=/var/log/jenkins/jenkins.log --webroot=/var/cache/jenkins/war"