dockerfile with windows path - windows

I would like to launch COPY command dockerfile for build image docker with copy bash file from host(windows 10) to ubuntu image like this :
COPY "C:\toto\directory_good\base.sh" /home/docker/scripts/base.sh
I try a lot of possibility but I always have the same error message :
lstat C:\base.sh: no such file or directory
I want to provisionning and configurate my container docker with some few bash file in my windows 10 OS.
What is the correct way to write path windows in Dockerfile. Do you have a example for more understand howto this ?

Use a relative path (not fully qualified with c:\, but relative to the build directory) and switch to forward slashes:
COPY scripts/base.sh /home/docker/scripts/base.sh
When you do a docker build -t myimg:latest ., the last . tells the docker client to send the current directory (excluding anything listed in .dockerignore) to the docker engine to do the build. Anything not included in that directory cannot be included with a COPY or ADD command. The standard process is to place your Dockerfile and all needed dependencies in a single folder, and do your build inside that folder.
Also note that 1.12 added the ability to change the escape character from the backslash that Linux/Unix uses to a backtick. This is defined in a special escape directive at the top of your Dockerfile, prefixed with a #. I wouldn't recommend doing this with images you're building for Linux hosts:
# escape=`
# Example Dockerfile with escape character changed
FROM windowsservercore
COPY testfile.txt c:\
RUN dir c:\

Related

Command not found in ssh but is in direcory

I am using an ssh account that connects to an external server, i have downloaded through guix some software like samtools and bedtools but when i try to use them in my directory it gives me this error:
-bash: samtools: command not found
In my direcory, however, there is the directry guix.profile and if I go into the bin folder of this, I have everything I downloaded.
What am I doing wrong?
Thank you
enter image description here
To run a file from the shell you need two things:
The shell must find the file
Being in the same directory does not enable the shell to find the file. You have to either supply an absolute or relative path the file, or have the directory in your PATH environment variable
In simplest terms this means instead of
$ samtools
try
$ ./samtools
The relative path tells the shell it wants that file
To run it from another directory, either use the whole absolute path, e.g. /home/yourname/samtools , or move the file into a directory that is on your $PATH
The file needs to be executable
If the file is not executable you will need
$ chmod +x ./samtools

I have tried and really need some help in understanding why docker file wont run this script

I am trying, as part of an exercise, to create an image and run a simple bash script. This is my Dockerfile:
FROM ubuntu
RUN chmod 700 .
#Create container to store file in
RUN mkdir doc-conatiner
# source then the destination of container in docker if I have one
COPY . /functionfibonnaci/doc-conatiner
#when conatiner starts what is the executable
CMD ["bash", "functionfibonnaci.sh"]
when I run docker run:
bash: functionfibonnaci.sh: No such file or directory```
No such file or direcotry
I have been at this for two days and just cant get this to work- so answers will be appreiacted.
As #KapilKhandelwal indicates in their answer, you're having trouble because the bash functionfibonnaci.sh command is looking for the script in the current directory, but you've never changed directories, so you're in the container filesystem's root directory.
I'd suggest updating this in a couple of ways:
On your host system, outside of Docker, make sure that the script starts with a "shebang" line; the very first line, starting at the very first character, should be #!/bin/sh (or if you have bash-specific extensions and can't remove them, #!/bin/bash, but try to stick to POSIX shell syntax if you can).
On your host system, outside of Docker, make sure the script is executable; chmod +x functionfibonnaci.sh. With this and the previous step, you'll be able to just run ./functionfibonnaci.sh without explicitly mentioning the shell.
In the Dockerfile, change WORKDIR to some directory early. Often a short directory name like /app works well.
You don't need to RUN mkdir the WORKDIR directory or directories you COPY into; Docker creates them for you.
When you COPY content into the Dockerfile, the right-hand side can be a relative path like ., relative to the current WORKDIR, so you don't need to repeat the directory name.
In your CMD you can also specify the script location relative to the current directory.
These updates will get you:
FROM ubuntu
# do not need to mkdir this directory first
WORKDIR /app # or /functionfibonnaci/doc-conatiner if you prefer
# copy the entire build-context directory into the current workdir
COPY . .
# the command does not need to explicitly name the interpreter
# (assuming the script has a "shebang" line and is executable)
CMD ["./functionfibonnaci.sh"]
From the error message, it is clear that functionfibonnaci.sh is not found.
Update the CMD command in the Dockerfile to this:
CMD ["bash", "/functionfibonnaci/doc-conatiner/functionfibonnaci.sh"]
Note: This will work if the functionfibonnaci.sh file is in the same directory where the Dockerfile is present on the host machine. If it is present in a different directory, feel free to update the path of the file in the CMD accordingly.
TL;DR
Let's look closely what you are trying to do. The first two lines of the Dockerfile are self-explainatory.
In the third command, you are creating a directory with the intention to copy your script files. Sounds good so far!!!
The fourth line of the Dockerfile is what created a mess IMO. You are actually copying all the files from host to the directory /functionfibonnaci/doc-conatiner. But wait, you were supposed to copy those file inside the doc-conatiner directory that you created earlier.. right?
Now in the last line of the Dockerfile, you are trying to run the bash script functionfibonnaci.sh. But now, since the default WORKDIR is / by default, it will search for the functionfibonnaci.sh file inside the / directory. This file is actually present inside the /functionfibonnaci/doc-conatiner directory.
Hence, you are facing this issue.

Dockerfile - copying a bash file from host to Dockerfile

I'm trying to copy a bash file called setup_envs.sh which is in the same directory of my Dockerfile.
How can I run this bash file only once after Dockerfile is created?
My code is (in the end of the Dockerfile):
RUN mkdir -p /scripts
COPY setup_env.sh /scripts
WORKDIR /scripts
RUN chmod +x /scripts/setup_env.sh
CMD [./scripts/setup_env.sh]
Current error:
/bin/bash: [./scripts/setup_env.sh]: No such file or directory
I don't have a type in the file btw, I checked this.
Moreover, after I solve this and run the image to create a container - how can I make sure this bash script is only called once? Should I just write a command in the bash script that checks if some folder exists - and if it does - don't install it?
Based on the different comments including mine, this is what your Dockerfile extract should be replaced with:
COPY --chmod 755 setup_env.sh /scripts/
WORKDIR /scripts
CMD /scripts/setup_env.sh
Alternatively you can use the exec form for CMD but there is not much added value here since you're not passing any command line parameters.
CMD ["/scripts/setup_env.sh"]
At this point, I'm not really sure the WORKDIR instruction is useful (it depends on the rest of your Dockerfile and the content of your script).
Regarding your single bash script execution, I think you need to give a bit more background on the exact goal you are targeting. I have the feeling you could be in an X/Y Problem. And since this is a totally different issue, it should go inside a new question anyway with all required details.

How to create a Dockerfile from scratch for Windows EXE file, which does not have any dependencies?

How to create a Dockerfile from scratch for Windows EXE file,
which does not have any dependencies?
I just did it on Linux, but can not find how to do it on windows (docker).
I did on Linux:
FROM scratch
ADD hello /
ENTRYPOINT ["/hello"]
g++ -o hello -static hello.cc
and it worked.
But how to make it work on windows?
Why it is impossible ?
How Microsoft create their base images ?
There is no scratch base image for Windows docker containers.
Microsoft publishes base images on hub.docker.com that you can use as an alternative.
The first line changes the escape character from \ to avoid escaping windows style paths.
# escape=`
FROM mcr.microsoft.com/windows/servercore:ltsc2019
ADD hello.exe C:\hello.exe
ENTRYPOINT ["C:\hello.exe"]
I think I found an answer how Microsoft creates base images:
docker import creates one image from one tarball which is not even an image (just a filesystem you want to import as an image)
Like this:
tar --numeric-owner --exclude=/proc --exclude=/sys -cvf centos6-base.tar /
cat centos6-base.tar | docker import - centos6-base
docker run -i -t centos6-base cat /etc/redhat-release

Windows Jenkins How do i use WORKSPACE system parameter when it has spaces?

I'm using Jenkins over windows 7 and i encountered strange behavior.
when im trying to copy files to working directory - represented in Jenkins by the system parameter WORKSPACE, for example like in this code:
cp -a hpdevops-discovery-demoapp-master/. $WORKSPACE/
i get the following:
cp -a hpdevops-discovery-demoapp-master/. 'C:\Program' Files '(x86)\Jenkins\workspace\jenkins-AutomationFreeStyle-Pipeline-2/'
cp: target '(x86)\Jenkins\workspace\jenkins-AutomationFreeStyle-Pipeline-2/' is not a directory
what's happening: the workspace located here: C:\Program' Files '(x86)\Jenkins\workspace\jenkins-AutomationFreeStyle-Pipeline-2/
but, because of the space in the path after the word 'Files' its deviding it into 2 and treating the second part - which is just half of the path, as the target path: '(x86)\Jenkins\workspace\jenkins-AutomationFreeStyle-Pipeline-2/'
i used to work with Jenkins on Linux and never had a problem like this when using the WORKSPACE system parameter.
anyone run into this?
use double quote wrap it like "$WORKSPACE"

Resources