The following is my root-directory:
andrej:
- docker/CodeExperiments.jar
- docker2/Dockerfile
Here are the contents of my Dockerfile:
FROM java:8
ADD docker/CodeExperiments.jar docker/
RUN javac BirthDayTask.java
And this is the command I am running:
docker build -t newfile docker2
Which results in the following error message:
ADD failed: stat /var/lib/docker/tmp/docker-builder946291442/docker/CodeExperiments.jar: no such file or directory
What am I doing wrong?
CodeExperiments is located in docker folder while Dockerfile is located in docker2.
Place them both in the same folder or at least place CodeExperiments in a child folder of the Dockerfile and reference from there.
When you
ADD docker/CodeExperiments.jar docker/
it is relative to the context directory, which is the directory named in the docker build command. That means you need to pass the current directory as the directory argument to docker build. By default it's looking for Dockerfile in that directory, so you also need a -f option to point at an alternate file.
Together this looks like:
docker build -t newfile -f docker2/Dockerfile .
Related
I am a Docker Beginner and I have some trouble with Dockerfile build..and a lot of questions
Do I have to start command build in path /var/lib/docker/builder ?
How do I know that it does not build because my Dockerfile is not correct written?
Do I have to call my folder Dockerfile?
docker build -t dokcerfile/xdebugphp .
than i got
Error response from daemon: unexpected error reading Dockerfile: read lstat /var/lib/docker/builder/Dokcerfile: no such file or directory
with
Get-Content Dockerfile | docker build -
Error response from daemon: the Dockerfile (Dockerfile) cannot be empty
You can launch docker build from any directory. If you try to COPY a file into an image that doesn't exist in the directory you name, you will see an error message that references /var/lib/docker, but that's an artifact of the Docker build implementation. (In fact, you really shouldn't look inside or try to directly use the /var/lib/docker directory at all.)
The file containing the build instructions is conventionally named Dockerfile (on systems with case-sensitive filesystems, with a capital D and no extension). It's most often located at the root of your source repository. This shouldn't be a directory.
The docker build -t option assigns a tag (name) to the image that's built. It doesn't have to correspond to a file on disk. If you're using Docker Hub to store your images (or just want to emulate its naming) these have the form username/imagename:version; there is an extended format if you're using some other Docker image registry.
You can name the Dockerfile something else; if you do, you need the docker build -f option to reference that file. If it's in a subdirectory of the repository root, the important detail is that COPY statements copy from the "context" directory you pass as the directory argument to docker build; this could be different from the directory that contains the Dockerfile. For example, if your Dockerfile has COPY index.php ., and you run docker build -f docker/xdebugphp ., the file is copied from the . current directory, which is the parent directory of the Dockerfile.
Looks like line endings, try changing dockerfile line endings to LF
Also for Docker build command you need to be in the directory where the dockerfile is or specify the path to the dockerfile
so in the directory where dockerfile is command is
docker build -t IMAGENAMEHERE .
So I solved it with this command
docker build -t imagename -f Dockerfile/xdebugphp .
I Have following structure in my project
I'm trying to run
following in cmd
docker build -t counter-bal-image '.\docker.'
My docker file has following line
COPY cicd/scripts/* /App/scripts/
When i run i get COPY failed: no source files were specified
How to copy relative folders?
If you build in ./docker then that's where everything must live. Instead specify the path to the Dockerfile but build in the current directory:
docker build -f docker/Dockerfile -t counter-bal-image .
Since you're building in . then ./cicd becomes accessible.
Dockerfile is:
FROM nginx
COPY html /usr/share/nginx/html
Dockerfile is in pwd directory(which is home/ubuntu/app), when use following command:
docker build -t mynginx .
I was giving an error:
copy failed: stat /var/lib/docker/tmp/docker-builder344/html: no such file or directory.
how to change docker source of the context of the build?
Docker build only look files in Dockerfile file context, mean the build will copy /home/ubuntu/app/ from this location where your Dockerfile is.
So better to place your html the /home/ubuntu/app in this location as docker build send tar of the context to docker daemon so it is recommended to keep the context minimal.
docker build -t mynginx . would expect to find Dockerfile in the current directory. Moreover, relative paths used by Dockerfile instructions would be relative to the current directory.
You can set the build context path to a different path docker build -t mynginx [some_folder_path]. Docker would search for Dockerfile there. You can modify the path to Dockerfile using -f option docker build -f [path_to_dockerfile] -t mynginx [some_folder_path]
I have Dockerfile defined in a directory
C:\work\Personal\API\api-service
Dockerfile
FROM maven:3.6.1-jdk-8 AS BUILD_IMAGE
COPY api-service /usr/src/app/api-service
COPY pom.xml /usr/src/app
RUN mvn -f /usr/src/app/pom.xml clean install
I am trying to run docker build C:\work\Personal\API\api-service from C:
This results in error saying
COPY failed: stat /var/lib/docker/tmp/docker-builder483308674/api-init-service: no such file or directory
In order from me to copy the source code from local machine to docker, i need to know the location of build context folder inside my Dockerfile.
Is there any way to access build context folder passed to docker build command inside a Dockerfile?
In my local machine i can run docker build command from same directory as Dockerfile is located. But from CI tool i will not know where the docker buildcommand will be executed. Hence if i know the docker build context path passed as argument, i can copy the source code into docker image based on the context path.
You don't need docker build context location known inside your dockerfile.
What you need to know is:
Location of you build context. (say C:\work\Personal\mycontext which contains files and folders that you need to copy inside docker container)
Location of dockerfile (say C:\work\Personal\API\api-service\Dockerfile)
Also you need to know relative file path structure of your context. Like
- C:\work\Personal\mycontext
|
- scripts
|
- start.sh
|
- create.py
|
- target
|
- maven
|
- abc.jar
In this case your dockerfile will contain appropriate commands like COPY scripts /scripts that copy these files assuming its running from the context folder C:\work\Personal\mycontext
Your docker build command will be
docker build -f C:\work\Personal\API\api-service\Dockerfile -t image:version1 C:\work\Personal\mycontext
Note: Here -f option specify location of dockerfile in this case its C:\work\Personal\API\api-service\Dockerfile and C:\work\Personal\mycontext specify location of docker build context.
Irrespective of location from where the docker build commands runs, it will work as long as you provide exact location of dockerfile and docker build context.
More info here.
Hope this helps.
I am trying to copy content of a directory while creating the docker image in the Dockerfile but while copying its giving me error-
COPY failed: stat
/var/lib/docker/tmp/docker-builder108255131/Users/user_1/media : no
such file or directory
I have the following file in the Dockerfile-
COPY /Users/user_1/media/. /code/project_media/
The media directory is in a seperate directory level then Dockerfile.
Sorry per dockerfile documentation:
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
https://docs.docker.com/engine/reference/builder/#copy
I usually will have a script for building the docker, and in that script will copy the files need for the COPY command into either the same directory or sub-directory of the "context of the build" (a very confusing way of saying the same directory as the dockerfile is in)
DOCKER_BUILD_DIR="./build/docker"
DOCKERFILE="./docker/Dockerfile"
MEDIA_FILES="/Users/user_1/media"
mkdir -p "${DOCKER_BUILD_DIR}/${MEDIA_FILES}"
cp -f "${DOCKERFILE}" "${DOCKER_BUILD_DIR}/"
cp -rf "${MEDIA_FILES}" "${DOCKER_BUILD_DIR}/${MEDIA_FILES}/.."
docker build "${DOCKER_BUILD_DIR}"