Upload local files to docker container - docker

There is the following code In my Dockerfile :
ENV GOVERS 073fc578434b
RUN cd /usr/local && curl -O http://go.googlecode.com/archive/$GOVERS.zip
RUN cd /usr/local && unzip -q $GOVERS.zip
the above code downloads the zip file to the /usr/local directory and all is ok. But now i do not want to download the zip file, I want to get the zip file from my local PC to the /usr/local at the docker container.

Let say the zip file is named test.zip and is located in the same directory as your Dockerfile, then you can make use of the COPY instruction in your dockerfile. You will then have:
COPY test.zip /usr/local/
RUN cd /usr/local && unzip -q test.zip
Furthermore you can use the ADD instruction instead of COPY to also uncompress the zip file and you won't need to RUN the unzip command:
ADD test.zip /usr/local/

Another approach that I am starting to like is using volumes and runtime commands. I don't like to have to rebuild the image if I change something incidental.
So I create a volume in the docker file to transfer stuff back and forth:
In Docker file:
RUN mkdir -p /someplace/dropbox
....
CMD ..... ; $POST_START ; tail -f /var/log/messages
on host:
mkdir /dropbox && cp ~/Downloads/fap.zip /dropbox \
docker run -v /dropbox:/someplace/dropbox \
-e POST_START="cp /someplace/dropbox/fap.zip /someplace-else; cd /someplace-else;unzip fap.zip" ..... <image>

Related

how to copy file unjar it and rename it in dockerfile

During docker build process i want to perform following task
download zip file using wget
copy the zip file to container at say /var/tmp/dest
unzip the zip file at dest /var/tmp/dest1 ==> result is say 1 file x.jar
copy the x.jar file from /var/tmp/dest1 to root location /
i am able to execute #1 2 and 3 steps but it fails with permission issue on #4
in docker file i am using
RUN cp /var/tmp/dest1/x.jar /
can we copy/or move the file from inside a container from one location to another ?
Here is the dockerfile contents
RUN wget --quiet --directory-prefix=/var/tmp/ --no-check-certificate
artifact-1.zip
RUN unzip /var/tmp/artifact-1.zip -d /var/tmp/
RUN cp /var/tmp/artifact-*.jar x.jar
RUN ls -ld / && ls -latr

local uaa docker image container not starting in windows docker

I have built a local uaa docker image and tried to run in local.
But I am getting this error when I am trying to start the docker image.
I built the docker image via this below command and the build is successful too.
docker build -t uaa-local --build-arg uaa_yml_name=local.yml .
when I am trying to run the local uaa docker image, I am getting this below error. What I am doing wrong
Content of DockerFile
FROM openjdk:11-jre
ARG uaa_yml_name=local.yml
ENV UAA_CONFIG_PATH /uaa
ENV CATALINA_HOME /tomcat
ADD run.sh /tmp/
ADD conf/$uaa_yml_name /uaa/uaa.yml
RUN chmod +x /tmp/run.sh
RUN wget -q https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.57/bin/apache-tomcat-8.5.57.tar.gz
RUN tar zxf apache-tomcat-8.5.57.tar.gz
RUN rm apache-tomcat-8.5.57.tar.gz
RUN mkdir /tomcat
RUN mv apache-tomcat-8.5.57/* /tomcat
RUN rm -rf /tomcat/webapps/*
ADD dist/cloudfoundry-identity-uaa-74.22.0.war /tomcat/webapps/
RUN mv /tomcat/webapps/cloudfoundry-identity-uaa-74.22.0.war /tomcat/webapps/ROOT.war
RUN mkdir -p /tomcat/webapps/ROOT && cd /tomcat/webapps/ROOT && unzip ../ROOT.war
ADD conf/log4j2.properties /tomcat/webapps/ROOT/WEB-INF/classes/log4j2.properties
RUN rm -rf /tomcat/webapps/ROOT.war
EXPOSE 8080
CMD ["/tmp/run.sh"]
On further investigation I think it is looking for run.sh file in the /tmp/ folder which is added on line 5 in Dockerfile..but when I checked for the file in /tmp/ folder it is not there..Is it because of that?And how to resolve that? I already have the run.sh in my current folder.

Run Dockerfile and move the output file into local machine

I have a Dockerfile that looks like the following.
FROM ubuntu:20.04
RUN apt-get update && \
rm -rf /var/lib/apt/lists/*
ADD part_aa /data/
ADD part_ab /data/
ADD part_ac /data/
ADD part_ad /data/
ADD part_ae /data/
ADD part_af /data/
ADD part_ag /data/
CMD entrypoint.sh
The Dockerfile adds some files into a directory called data, and at the end entrypoint.sh merges together the files that are in the data directory into a single file.
How can I mount a volume so I can move the final output file into my local machine?
I know that I can use the -v flag (volume), but I cannot figure out how to incorporate it into running the the image.
The entrypoint.sh looks like this:
cd /data
MODEL_FILE="merged_file"
if [ ! -f "$MODEL_FILE" ]; then
echo "combining model file parts."
cat part_* > $MODEL_FILE
echo "combining model file parts done"
fi
A Dockerfile is used to build a docker image. The -v switch is applicable when you run an image... you are mixing two things: building and running a docker image.

Why Dockerfile builds but is not working correctly, even though it works manually?

I've been trying to get this running for many MANY hours. I've been scouting docker docs, github repos and other stuff but I can't get it working for some reason.
My dockerfile:
FROM mattrayner/lamp:latest-1804
WORKDIR /app
RUN wget -O /tmp/lwt.zip http://downloads.sourceforge.net/project/lwt/lwt_v_1_6_3.zip && \
yes A | unzip /tmp/lwt.zip &&\
rm /tmp/lwt.zip &&\
mv connect_xampp.inc.php connect.inc.php
EXPOSE 80
CMD ["/run.sh"]
It build normally without any errors but when I run the image nothing appears in the /app directory and I get just a basic Welcome to LAMP view on my browser.
Though,
If I do docker run -p "80:80" -it -v ${PWD}/app:/app mattrayner/lamp:latest-1804 /bin/bash, cd /app, copy and paste
wget -O /tmp/lwt.zip http://downloads.sourceforge.net/project/lwt/lwt_v_1_6_3.zip && \
yes A | unzip /tmp/lwt.zip &&\
rm /tmp/lwt.zip &&\
mv connect_xampp.inc.php connect.inc.php
it still doesn't work BUT if I exit and run the same docker run command it works.
Docker LAMP instructions also state to do exactly as I have done:
FROM mattrayner/lamp:latest-1804
# Your custom commands
CMD ["/run.sh"]
As I followed these instructions I thought that everything would work nicely.
What's the catch here? It has something to do with the intermediate containers probably but I can't comprehend it (I'm not a devops or developer by trade, just a hobbyist).
That happens because you're doing this:
Download a file (wget ...) in your /app dir in your docker image.
After that, you're overwritting this /app dir when you mount volume, with content of your $PWD/app.
If you are installing something doing docker build in some dirs, don't mount into the same path.
If you need something in the same path, you can mount some concrete files, but not the whole dir, or it will override what you had in your docker image when container is created.
You can do wget somewhere else or download it into your ${PWD}/app and then mount it.

How to copy file in Docker?

I have the following Dockerfile:
FROM sonarqube
RUN wget https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/4.0.0/sonar-gitlab-plugin-4.0.0.jar
COPY sonar-gitlab-plugin-4.0.0.jar /opt/sonarqube/extensions/plugins/
And I get the following error while copying the file:
Removing intermediate container 63a3ae1d7390
Step 3/3 : COPY sonar-gitlab-plugin-4.0.0.jar /opt/sonarqube/extensions/plugins/
lstat sonar-gitlab-plugin-4.0.0.jar: no such file or directory
How can I copy the file in this case?
You are trying to copy a file located in your container as if it was a local file, so Docker is unable to find it.
Use ADD like this should make it work :
FROM sonarqube
ADD https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/4.0.0/sonar-gitlab-plugin-4.0.0.jar /opt/sonarqube/extensions/plugins/
it's more "dockerlike"
You're running wget inside the container, but then trying to COPY it from the host machine to the container. To copy from one container location to another simply use cp:
RUN wget https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/4.0.0/sonar-gitlab-plugin-4.0.0.jar \
&& cp sonar-gitlab-plugin-4.0.0.jar /opt/sonarqube/extensions/plugins/
Better yet, just use wget -O to save the file in the desired location from the get go.
RUN wget -o /opt/sonarqube/extensions/plugins/ \
https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/4.0.0/sonar-gitlab-plugin-4.0.0.jar
COPY command copies file from the host to the container.
For any command you want to run inside the container you need RUN:
RUN wget https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/4.0.0/sonar-gitlab-plugin-4.0.0.jar \
&& cp sonar-gitlab-plugin-4.0.0.jar /opt/sonarqube/extensions/plugins/

Resources