Files after docker build missing in the image - windows

i am currently trying to build a windows iis docker image. The Dockerfile is in the folder where the files are that has to get into the docker file. I thought it would be automatically moved in, but i cant find the folder in there.
Is it possible to move the files surrouding the docker file into the docker image?
Thanks!

you can copy all the files by putting the copy command in your docker file:
COPY . .

Related

Copy folder from Windows host OS into Docker image using COPY in Docker file

I want to copy folder D:\test from my host OS (Windows) to my docker image.
My Docker file is D:\Programs>
Docker file
FROM mcr.microsoft.com/windows/servercore:ltsc2019
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN mkdir root
RUN cd root
WORKDIR /root
RUN mkdir test
COPY D:/test to /root/test
#USING 'COPY' here instead of 'ADD' because of https://stackoverflow.com/questions/24958140/what-is-the-difference-between-the-copy-and-add-commands-in-a-dockerfile
From folder D:\Programs> I run command docker build . -t test
But I get error:
COPY failed: file not found in build context or excluded by .dockerignore: stat test: file does not exist
I tried commands COPY D:/test to /root/test and COPY ./test to /root/test
I know this error occurs because the path I copy from has to be relative from the build context (the . in docker build .). It cannot be an arbitrary path on the system outside of the build context.
I thought by using . I'd be in context D:\ from my build context D:\Programs>, but I guess not. What should my COPY command look like?
I checked here already:
https://forums.docker.com/t/copy-files-from-windows-host-to-ubuntu-container/28757
Dockerfile COPY from a Windows file system to a docker container
Dockerfile: Copy directory from Windows host to docker container
UPDATE 1
I placed the test folder in D:\Programs where my Dockerfile also resides, so I now have structure:
D:\Programs
\Test
Dockerfile
I then ran the build command again where I tried COPY test to /root/test and COPY ./test to /root/test, but both fail with the same aforementioned error.
I assume you've only added to in COPY D:/test to /root/test for abbreviation but I recommend checking that anyway.
If you really need what's in D:/Programs and can't move it to a folder inside the current build context there are two general options as I see it:
changing the build context - I'd suggest setting the build context as D:/ and adding every folder in the D:/ directory other than Programs to the .dockerignore file, then you can reference the Dockerfile from some subdirectory somewhere in D:/ and copy your files at build time as you wanted
creating a bind mount in runtime - you can map the D:/Programs directory to a folder inside the container (/my-programs) at runtime then copy the files from that folder to /root/test or just use the bind mount folder (/my-programs)
If in the future it will be available to use bind mounts in build time you'd be able to use the second option while creating the docker image
The only way I know how to do this is to change the dockerfile location during build, keeping the copied folder in context.
As below:
'test' folder located at D:/test
Set dockerfile COPY command as such:
COPY test /root/test
Say dockerfile is at D:/Programs/dockerfile
Navigate to D:/ in CLI
docker build -f ./Programs/dockerfile .
The . keeps the "test" folder in the build context. As far as I know, you cannot go to a parent directory etc. with docker build, so instead you want to stay in the parent folder and go down to the dockerfile.
If you run the docker build ... from D:\Programs that folder is the docker build context. All files used in the Dockerfile must be there.
d:\files is outside d:\programs, so it will be never be found.
You need to copy files content to the places where you run the command and you can use this copy line
COPY samplefile1.txt /root/test

cannot create custom folders in docker logstash image based container

i'm using logstash image and i have some ruby scripts that are located in the same directory as my dockerfile.
my goal is to create a script folder, and copy my scripts to it.
my problem is that when i access to the container instance, the folder is not created and no ruby file exist.
this is my dockerfile
FROM docker.elastic.co/logstash/logstash:${ELK_VERSION}
USER root
WORKDIR /usr/share/logstash
RUN mkdir scripts
COPY ./scripts/*.rb scripts
thanks in advance.
EDIT 1:
this is the files structure

How can I edit files in a Docker container from an editor on my host?

I'm new here, so appreciate your patience with my question.
I have a container which has 5 folders with files that I want to modify via Visual Studio Code outside the container, not with Nano or any other editor in the container itself.
I've seen many recommendations to mount a volume. How can I go about trying that?
Map the host folder to a folder mounted in the image.
docker run -it -v /hostdir:/dockerdir 'imageName'.
Now you can put all the folders in dockerdir or mount them all and work on the files from outside the container.

How do I copy "with execute permissions" in a docker file used to create a ubuntu container on docker for windows

I have a docker file that copies a file tree to the container using the command in the docker file:
COPY image /
Docker copies all the files BUT the .sh and .py etc files in the source folder ( on windows ) have execute permission turned on. When the container is run the copies present in the container DO NOT have execute permission turned on?
How do I deal with this other than explicitly chmod +x the files in the docker file when building the container (having to maintain a list of them etc) in this situation.

Copy files to docker image after build

I do have an already build docker image and wan't to add files to it AFTER the build was done. Is there a way to add files without rebuilding it (or maybe to add it and save it with an new tag)? I did find docker cp but if I understand that right it does only work in running containers.
docker cp but if I understand that right it does only work in running containers
Still, that might work considering you can then commit a container into a new image.
See docker commit.
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

Resources