Docker COPY issue while building the docker image - docker

I have a project which is Maven based multi module project
It has various modules with in, like common-utils, web, theme, etc, etc
And also in the root location it has the Dockerfile which is not default one but I have named it Dockerfile.cli due to some requirements
Dockerfile.cli contents here:-
FROM tomcat
ENV NEUW_LOG_HOME /neuw/web/logs
RUN echo "running the image, making it a container :-)"
RUN mkdir -p "/neuw/web/theme-v4"
COPY web/target/web.war /usr/local/tomcat/webapps/ROOT.war
COPY theme-v4 /neuw/web/theme-v4
CMD ["catalina.sh", "jpda", "run"]
Now why I am here -> am getting the below error while building the image:-
COPY failed: stat /var/lib/docker/tmp/docker-builder838877607/web/target/web.war: no such file or directory
The command I use to run the image build is like below and running it on the root of the project which contains both theme and web folder:-
docker build -f Dockerfile.cli -t neuw/web:snapshot-30 .
Any hints and help for the issue?

Which directory are you in when you run this command? Could you do ls /web/target/ from that directory? I ask because I think your Dockerfile is expecting to find a web.war in ./web/target relative to the directory you are running in.
Edit (to save anyone digging through the comments on this): The target directory did contain the file but it was invisible to docker due to a .dockerignore file with **/target.

Related

Mis-understand of copy file in docker images

Hello could someone pleas help me on copying docker(I'm starter) host file into my jupyter/pyspark-notebook images. I've pulled this notebook from docker as public available.
I've created a Dockerfile which contains this.
FROM jupyter/pyspark-notebook:latest
ADD /home/abdoulaye/Documents/M2BIGDATA/Jaziri /bin/bash
I've changed /bin/bash to . but nothing is visible.
when I execute docker built it's like it copy files as shown in output below.
when I go to my my notebook I did note found folders. I check my snapshot if I can found these copied folder but I'm very confused.
In clear, I've an running notebook in my docker I use it in y navigator but I can not load data. I like to copy data in place where I can access it in notebook.
You can not copy using absoult path, the path should be relative to Dockerfile, so /home/abdoulaye/Documents/M2BIGDATA/Jaziri this path inside Dockerfile is not correct. Copy file to Dockerfile context and then copy like
ADD M2BIGDATA/Jaziri /work
Now First thing, you should not copy files from host to executable files directory.
For instance,
FROM alpine
copy hello.txt /bin/sh
If you copy like this, it will create a problem to run command inside container as sh or bash will be replaced or corrupt.
2nd, while you are building the docker image with invalid context, it should be the same where your Dockerfile is, so better to run the directory where you place the Dockerfile.
docker build -t my-jupyter .
3rd, you should not run cp command inside container to copy files from host to container.
docker cp /home/abdoulaye/Documents/M2BIGDATA/Jaziri container_id:/work
it will copy your files to /work path of the container.

List all files in Build Context and/or in WORKDIR when building container image

I am trying to build a container image using Docker task on Azure Pipeline.
I created a dockerfile, but it looks like a made a mistake cause I keep getting
WARN saveError ENOENT: no such file or directory, open
'/usr/src/app/package.json'
I thought it would be good to list all files that exist in build context and/or WORKDIR so it
would be easier for me to find a solution.
Is there any appropriate dockerfile command, something like...
dir
ls
RUN. You can run any command you want in a container.
RUN ls will run ls and print the output of the command.

Troubleshoot directory path error in COPY command in docker file

I am using COPY command in my docker file on top of ubuntu 16.04. I am getting error as no such file or directory eventhough the directory is present. In the below docker file I want to copy the directory "auth" present inside workspace directory to the docker image (at path /home/ubuntu) and then build the image.
FROM ubuntu:16.04
RUN apt-get update
COPY /home/ubuntu/authentication/workspace /home/ubuntu
WORKDIR /home/ubuntu/auth
a Dockerfile COPY command can only refer to files under the context - the current location of the Dockerfile, aka .
so you have a few options now:
if it is possible to copy the /home/ubuntu/authentication/workspace/ directory content to somewhere inside your project before the build (so now it will be included in your Dockerfile context and you can access it via COPY ./path/to/content /home/ubuntu) it can be great. but sometimes you dont want it.
instead of copying the directory, bind it to your container via a volume:
when you run the container, add a -v option:
docker run [....] -v /home/ubuntu/authentication/workspace:/home/ubuntu [...]
mind that a volume is designed so any change you made inside the container dir(/home/ubuntu) will affect the bound directory on your host side (/home/ubuntu/authentication/workspace) and vice versa.
i found a something over here: this guy is forcing the Dockerfile to accept his context- he is sitting inside the /home/ubuntu/authentication/workspace/ directory, and running there
docker build . -f /path/to/Dockerfile
so now inside his Dockerfile he can refer to /home/ubuntu/authentication/workspace as his context (.)

Docker starts looking for src folder in wrong directory

So, I am new to Docker but after trying a couple of times I can't get this to work.
Basically I have a simple script like this:
Dockerfile
from centos:7
.....
COPY /C:/Users/Kalin/Drive/web/sites/foo.com/ /var/www
EXPOSE 80
Whenever I run docker build everything works as planned except at the COPY part I get this error:
Step 10/11 : COPY /C:/Users/Kalin/Drive/web/sites/foo.com/ /var/www
COPY failed: stat /var/lib/docker/tmp/docker-builder646917435/C:/Users/Kalin/Drive/web/Kalin/foo.com: no such file or directory
I get the error is about not finding a directory, but instead of looking for it starting from C:/.. foldedr it is looking from /var/...
I don't know what mistake I am doing
I would strongly suggest to make relative path in COPY command so if you have your docker file in /C:/Users/Kalin and you are running docker build from that folder, just place Drive/web/sites/foo.com/ in COPY command

docker copy issues and set host env variable

I am new to docker.
I would like to understand the following questions. I have been searching but I can't find the answers to my questions.
Why do I always get a wrong path when I tried to copy the file?
Does that mean I can only copy the files into the docker image from the same directory where I have my dockerfile? Is there a way to COPY files from other directories on the host?
Is there a way to passing in host's environment variables directly in the Dockerfile without using "ARG" and --build-arg flag?
Below is what I currently have
file structure is like this:
/home/user1/docker
|__ Dockerfile
In the Dockerfile:
From
ARG BLD_DIR=/tmp
RUN mkdir /workdir
WORKDIR /workdir
COPY ${BLD_DIR}/a.file /workdir
I ran
root#localhost> echo $BLD_DIR
/tmp/build <-- BLD_DIR is a custom variable; meaning it's different on each dev env
docker build --build-arg BLD_DIR=${BLD_DIR} -t docker-test:1.0 -f Dockerfile
Always got error like
COPY failed: stat
/var/lib/docker/tmp/docker-builder035089075/tmp/build/a.file: no such file
or directory
In a Dockerfile, you can only copy files that are available in the current Docker build context.
By default, all files in the directory where you run your docker build command are copied to the Docker context folder.
So, when you use ADD or COPY commands, all your paths are in fact relative to build folder, as the documentation states:
Multiple resources may be specified but the paths of files and directories will be interpreted as relative to the source of the context of the build.
This is voluntary because building an image using docker build should not depend on auxiliary files on your system: the same Docker image should not be different if built on 2 different machines.
However, you can have a directory structure like such:
/home/user1/
|___file1
|___docker/
|___|___ Dockerfile
If you run docker build -t test -f docker/Dockerfile . in the /home/user1 folder, your build context will be /home/user1, so you can COPY file1 in your Dockerfile.
For the very same reason, you cannot use environment variables directly in a Dockerfile. The idea is that your docker build command should "pack" all the information needed to generate the same image on 2 different systems.
However, you can hack your way around it using docker-compose, like explaned here: Pass host environment variables to dockerfile.

Resources