Docker: cannot copy file within the container - docker

This is not about transferring files between host and container, it's just inside the container.
app.js exists in the build directory.
Step 7 : RUN ls build
---> Running in 8461a550a5db
app.js
app.js.map
css
html
img
js
---> 22a863b60265
Should be copied to the static folder.
Removing intermediate container 8e195477d342
Step 9 : RUN cp build/app.js static/
---> Running in 0a49669338e0
---> 41cb4d3039d1
But it's not there. Why?
Removing intermediate container 0a49669338e0
Step 10 : RUN ls static/
---> Running in 4cdb5f74a722
css
html
img
js
Tried: RUN cp ./build/app.js ./static/ - doesn't work either.

Could you try to use docker build with no-cache?
docker build -t "your_app" --no-cache=true .
Problem here:
Removing intermediate container 0a49669338e0
From Docker docs: https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#build-cache
During the process of building an image Docker will step through the
instructions in your Dockerfile executing each in the order specified.
As each instruction is examined Docker will look for an existing image
in its cache that it can reuse, rather than creating a new (duplicate)
image. If you do not want to use the cache at all you can use the
--no-cache=true option on the docker build command.

Related

Trying to run an executable inside of the Program files (x86) directory in a dockerfile throws an error

I am new to docker. Excuse my ignorance on this topic.
I created a dockerfile with the intent on running the windows steam application. this is my docker file.
# escape=`
FROM mcr.microsoft.com/windows/servercore:ltsc2019
ADD https://steamcdn-a.akamaihd.net/client/installer/SteamSetup.exe c:\SteamSetup.exe
RUN c:\SteamSetup.exe /S
ENTRYPOINT ["c:\Program Files (x86)\Steam\Steam.exe"]
I verified that in the docker image Steam is installed at c:\Program Files (x86)\Steam\Steam.exe I attached to the docker with a powershell entrypoint and was able to run "& c:\Program Files (x86)\Steam\Steam.exe" I cannot however get the docker image to launch steam on its own. I gt the error below.
PS C:\Users\AJWHEELE\Desktop\dockers\steamOS> docker build -t ajwtech/windowstest .
Sending build context to Docker daemon 2.048kB
Step 1/4 : FROM mcr.microsoft.com/windows/servercore:ltsc2019
---> 80e84fd280e2
Step 2/4 : ADD https://steamcdn-a.akamaihd.net/client/installer/SteamSetup.exe c:\SteamSetup.exe
Downloading [==================================================>] 1.574MB/1.574MB
---> Using cache
---> d39ad50d3754
Step 3/4 : RUN c:\SteamSetup.exe /S
---> Using cache
---> 33cdd5566dad
Step 4/4 : ENTRYPOINT ["c:\Program Files (x86)\Steam\Steam.exe"]
---> Running in 65027c59352a
Removing intermediate container 65027c59352a
---> e92095819109
Successfully built e92095819109
Successfully tagged ajwtech/windowstest:latest
PS C:\Users\AJWHEELE\Desktop\dockers\steamOS> docker run --rm -e DISPLAY=192.168.1.119:0 ajwtech/windowstest:latest
The filename, directory name, or volume label syntax is incorrect.
PS C:\Users\AJWHEELE\Desktop\dockers\steamOS>
Also I am trying to get Steam to launch so that I can see the user interface. currently I am on a windows 10 machine trying to use VcXsrv.
Thanks,
Adam

Docker COPY does not cp

i would like to build my first Docker image, containing Apache Tomcat and a deployed web app. My Dockerfile is really small, based on Tomcat:8.0 image and is supposed to copy a WAR file into Tomcat's appBase.
Build of the image reports success, but the file is nowhere to be found in the container.
Copying from host to the container work w/o issues using "docker cp":
[root#edubox dock]# docker cp jdbcdemo_3.war 15dd44bbf992:/usr/local/tomcat/webapps/
My Dockerfile:
# we are extending everything from tomcat:8.0 image ...
FROM tomcat:8.0
MAINTAINER simo
# COPY path-to-your-application-war path-to-webapps-in-docker-tomcat
COPY ./jdbcdemo_3.war /usr/local/tomcat/webapps/
EXPOSE 8082
Image build:
root#edubox dock]# docker image build -t simo/jdbcdemo_3 --tag=recent ./
Sending build context to Docker daemon 10.24 kB
Step 1/4 : FROM tomcat:8.0
---> ef6a7c98d192
Step 2/4 : MAINTAINER simo
---> Using cache
---> 54d824d7258b
Step 3/4 : COPY ./jdbcdemo_3.war /usr/local/tomcat/webapps/
---> Using cache
---> f94330423a93
Step 4/4 : EXPOSE 8082
---> Running in 74b6dd0364b2
---> 9464f11ac18e
Removing intermediate container 74b6dd0364b2
Successfully built 9464f11ac18e
I would expect COPY to place the file where specified or an error message because of which this does not work.
Please try this way,
Keep the "jdbcdemo_3.war" where your Dockerfile exists. And make this change in the Dockerfile.
(remove ./ from your Dockerfile) like,
COPY jdbcdemo_3.war /usr/local/tomcat/webapps/
please check the permission side of the file.
you can give full permission and test once. (user:group)
try this: COPY jdbcdemo_3.war /tmp
In your Dockerfile. And build the image and check in the /tmp directory. If the file copied successfully, give the permission to /usr/local/tomcat/webapps/ Or copy to /tmp first and then copy from /tmp to /usr/local/tomcat/webapps/. Using COPY command in Dockerfile
Hi and many thanks for offering advice. The issue has been trivial in the end. I have not been examining the correct container.
I did not realize one needs to pick the freshly created image, run the container with this image and only afterwards peek for changes described in the Dockerfile in that container.
I have been looking into parent container which i now understand could not have worked.
Sry for wasting your time ;-)

Dockerfile: mkdir and COPY commands run fine but I can't see the directory and file

I am using jenkins image to create a docker container. For now I am just trying to create a new directory and copy a couple of files. The image build process runs fine but when I start the container I cannot see the files and the directory.
Here is my dockerfile
FROM jenkins:2.46.1
MAINTAINER MandeepSinghGulati
USER jenkins
RUN mkdir /var/jenkins_home/aws
COPY aws/config /var/jenkins_home/aws/
COPY aws/credentials /var/jenkins_home/aws/
I found a similar question here but it seems different because I am not creating the jenkins user. It already exists with home directory /var/jenkins_home/. Not sure what I am doing wrong
Here is how I am building my image and starting the container:
➜ jenkins_test docker build -t "test" .
Sending build context to Docker daemon 5.632 kB
Step 1/6 : FROM jenkins:2.46.1
---> 04c1dd56a3d8
Step 2/6 : MAINTAINER MandeepSinghGulati
---> Using cache
---> 7f76c0f7fc2d
Step 3/6 : USER jenkins
---> Running in 5dcbf4ef9f82
---> 6a64edc2d2cb
Removing intermediate container 5dcbf4ef9f82
Step 4/6 : RUN mkdir /var/jenkins_home/aws
---> Running in 1eb86a351beb
---> b42587697aec
Removing intermediate container 1eb86a351beb
Step 5/6 : COPY aws/config /var/jenkins_home/aws/
---> a9d9a28fd777
Removing intermediate container ca4a708edc6e
Step 6/6 : COPY aws/credentials /var/jenkins_home/aws/
---> 9f9ee5a603a1
Removing intermediate container 592ad0031f49
Successfully built 9f9ee5a603a1
➜ jenkins_test docker run -it -v $HOME/jenkins:/var/jenkins_home -p 8080:8080 --name=test-container test
If I run the command without the volume mount, I can see the copied files and the directory. However with the volume mount I cannot see the same. Even if I empty the directory on the host machine. Is this the expected behaviour? How can I copy over files to the directory being used as a volume ?
Existing volumes can be mounted with
docker container run -v MY-VOLUME:/var/jenkins_home ...
Furthermore, the documentation of COPY states:
All new files and directories are created with a UID and GID of 0.
So COPY does not reflect your USER directive. This seems to be the second part of your problem.

How to persist changes made by maven dependency:go-offline in docker image

I'm Test Automation engineer and working in big product company. Companies big monolithic project being divided and parts are departuring into clouds. As part of such redesign Test Automation projects should also get cloudy. Our typical TA project based on groovy, selenium, testng and maven. Now I want to try the option of putting whole TA maven project into Docker image\container. Its works well, but on the very first run it starts download dependencies into local .m2 repository. I want to speed up and have this task done on a creation image stage.
Here is a my DOCKERFILE:
FROM maven:3.3-jdk-8
LABEL description="Embedded portal-web-testing"
MAINTAINER NNN
COPY ./settings.xml /root/.m2/
COPY ./acceptance-tests ./acceptance-tests
WORKDIR acceptance-tests
RUN mvn dependency:go-offline --debug >log
RUN ls /root/.m2/
#RUN mvn test
ENTRYPOINT ["bash"]
And here is a log:
Step 1 : FROM maven:3.3-jdk-8
---> 7addddbdd730
Step 2 : LABEL description "Embedded portal-web-testing"
---> Running in 1d195ccb9c57
---> f5372b024ca0
Removing intermediate container 1d195ccb9c57
Step 3 : MAINTAINER NNN
---> Running in 03ebbffda680
---> cb12da3d8ec6
Removing intermediate container 03ebbffda680
Step 4 : COPY ./settings.xml /root/.m2/
---> 164999e1f63a
Removing intermediate container 1e1778d2533b
Step 5 : COPY ./acceptance-tests ./acceptance-tests
---> 7d93fff4193e
Removing intermediate container a5d04eb30591
Step 6 : WORKDIR acceptance-tests
---> Running in f15111475fc6
---> beb4d090362b
Removing intermediate container f15111475fc6
Step 7 : RUN mvn dependency:go-offline --debug >log
---> Running in 2c09f1869143
---> 62326c2bb073
Removing intermediate container 2c09f1869143
Step 8 : RUN ls /root/.m2/
---> Running in 91b602f529da
settings.xml
---> b7bc32199ab3
Removing intermediate container 91b602f529da
Step 9 : ENTRYPOINT bash
---> Running in 3167f5a6d923
---> 94b3e0b146da
Removing intermediate container 3167f5a6d923
Successfully built 94b3e0b146da
On Step 7 surely files being downloaded, but looks like not stored.
Following console command shows that there are no updates in local .m2 folder:
root#37f5a0d04232:/acceptance-tests# ls /root/.m2
settings.xml
If I try to run same command again from command line inside a container (when image is created and container had started):
root#37f5a0d04232:/acceptance-tests# mvn dependency:go-offline
Massive downloads starts and repository folder finally appeared under .m2
root#37f5a0d04232:/acceptance-tests# ls /root/.m2
repository settings.xml
I struggle to understand why changes caused by maven command from Dockerbuild file did not stored as docker layer.
I am using Docker 1.12 and maven 3.3.3
/root/.m2 is a volume that is why it gets cleared when docker container is launched. This can be avoided by caching the content in a custom directory and then copying it to /root/.m2 when container is launched.
Fortunately maven image is pre-baked with all the copying logic so you just have to point repository as:
RUN mvn -B -f /tmp/pom.xml -s /usr/share/maven/ref/settings-docker.xml dependency:resolve
The entry-point will take care of setting local repository for you. It helped me hope it helps you as well.
Also, for reference visit.

Dockerfile COPY instruction failing?

All, i'm trying to persistently copy files from my host to an image so those files are available with every container launched based on that image. Running on debian wheezy 64bit as virtualbox guest.
the Dockerfile is fairly simple (installing octave image):
FROM debian:jessie
MAINTAINER GG_Python <[redacted]#gmail.com>
RUN apt-get update
RUN apt-get update
RUN apt-get install -y octave octave-image octave-missing-functions octave-nan octave-statistics
RUN mkdir /octave
RUN mkdir /octave/libs
RUN mkdir /octave/libs/jsonlab
COPY ~/octave/jsonlab/loadjson.m /octave/libs/jsonlab/.
I'm getting the following trace after issuing a build command: docker build -t octave .
Sending build context to Docker daemon 423.9 kB
Sending build context to Docker daemon
Step 0 : FROM debian:jessie
---> 58052b122b60
Step 1 : MAINTAINER GG_Python <[..]#gmail.com>
---> Using cache
---> 90d2dd2f7ee8
Step 2 : RUN apt-get update
---> Using cache
---> 4c72c25cd829
Step 3 : RUN apt-get update
---> Using cache
---> b52f0bcb9f86
Step 4 : RUN apt-get install -y octave octave-image octave-missing-functions octave-nan octave-statistics
---> Using cache
---> f0637ab96d5e
Step 5 : RUN mkdir /octave
---> Using cache
---> a2d278b2819b
Step 6 : RUN mkdir /octave/libs
---> Using cache
---> 65efbbe01c99
Step 7 : RUN mkdir /octave/libs/jsonlab
---> Using cache
---> e41b80901266
Step 8 : COPY ~/octave/jsonlab/loadjson.m /octave/libs/jsonlab/.
INFO[0000] ~/octave/jsonlab/loadjson.m: no such file or directory
Docker absolutely refuses to copy this file from the host into the image. Needless to say a the file loadjson.m is there (cat displays), all my attempts to change the path (relative, absolute, etc.) failed. Any advice why this simple task is problematic?
At the time I originally wrote this, Docker didn’t expand ~ or $HOME. Now it does some expansions inside the build context, but even so they are probably not what you want—they aren’t your home directory outside the context. You need to reference the file explicitly, or package it relative to the Dockerfile itself.
Docker can only copy files from the context, the folder you are minus any file listed in the dockerignore file.
When you run 'docker build' docker tars the context and it sends it to the docker daemon you are connected to. It only lets you copy files inside of the context because the daemon might be a remote machine.
I couldn't get COPY to work until I understood the context (I was trying to copy a file from outside of the context)
The docker build command builds an image from a Dockerfile and a context. The build’s context is the files at a specified location PATH. The PATH is a directory on your local filesystem.
A context is processed recursively. So, a PATH includes any subdirectories.
The build is run by the Docker daemon, not by the CLI. The first thing a build process does is send the entire context (recursively) to the daemon. In most cases, it’s best to start with an empty directory as context and keep your Dockerfile in that directory. Add only the files needed for building the Dockerfile.
Warning: Do not use your root directory, /, as the PATH as it causes the build to transfer the entire contents of your hard drive to the Docker daemon.
Reference:
https://docs.docker.com/engine/reference/builder/#usage
I had similar issue. I solved it by checking two things:
Inside your, docker-compose.yaml check context of the service, docker will not copy any file outside of this directory. For example if the context is app/ then you cannot copy anything from ../app
Check .dockerignore to be sure that you are not ignoring the file you want to copy.
I got it working by first checking what the context was,
setting an absolute path before the source file in
your Dockerfile to get that information:
# grep COPY Dockerfile
COPY /path/to/foo /whatever/path/in/destination/foo
Building with that:
docker build -t bar/foo .
you'll get an error, which states the context-path that Docker
is apparently looking into for its files, e.g.
it turns out to be:
/var/lib/docker/tmp # I don't remember
Copying(!) your set of build-files in that directory (here: /var/lib/docker/tmp),
cd into it, build from there.
See if that works, and don't forget to do some housekeeping cleaning up
the tmp, deleting your files before the next visit(or).
HTH
Michael
Got this error using a Dockerfile for a linux container on a Windows machine:
#24 1.160 Skipping project "/src/Common/MetaData/Metadata.csproj" because it was not found.
Restore worked perfectly on the host machine.
Turned out to be the error mentioned here:
https://stackoverflow.com/a/68592423/3850405
A .csproj file did not match casing in Visual Studio vs the file system.

Resources