docker env: bash\r: No such file or directory - windows

While locally deploying an app in PyCharm on windows10, I have encountered several mistakes.
Make test command returned following mistake:
service "core" is not running container #1
make: *** [Makefile:60: test] Error 1
And indeed container status with the command make ps returned exited(127). When I have checked docker logs for the container in question, I've seen:
/usr/bin/env: ‘bash\r’: No such file or directory
In this thread, this mistake is connected to how windows processes line endings of files from different OS. The usual solution is:
git config --global core.autocrlf false
But after running the code and updating current git repo and restarting the containers, i still get the same mistake. What might be the issue here?

What did helped me
I assume that the problem was in the windows line endings in the Unix-based containers.
To solve it I found two very helpful instructions:
Configure your line separators in the PyCharm https://www.jetbrains.com/help/pycharm/configuring-line-endings-and-line-separators.html
To clarify that changes were really enabled, I have checked the files in the notepad++
https://notepad-plus-plus.org/downloads/v8.1.9.3/
Also it was helpful to check the original code because part of the problem was the incorrect spelling of some commands.

When I use Windows in Docker and run a bash script, I have a similar problem, which I solve by using LF instead of CRLDF as the line separator.
in vscode, we can change it here

Related

Bash github project fails to run when cloned on WSL Ubuntu

I have a simple bash script written on a WSL Ubuntu system; it runs perfectly there. I then git push it up to github, and go to a different systems WSL Ubuntu and git clone the project, cd into that folder and run the script, but it is broken with the below errors.
I tried dos2unix on it, but this does not work, same errors and same broken state. Do you have some suggestions about what might be causing this (something is changed by storing it in github I guess), and how to fix (as before, none of the below errors are seen on the originating WSL Ubuntu system, where the script runs perfectly)?
: command not found
: command not found
: command not found
: invalid shell option name
: command not found
: command not found
-bash: .custom: line 147: syntax error near unexpected token `$'{\r''
'bash: .custom: line 147: `fnheader() {
I had the same problem with Windows line endings, so my solution was:
# Remove cloned repo
git config --global core.autocrlf input
# Clone again the repo
Let me know if it works for you too.
Regards.

Failed to launch git bash

The terminal process command 'C:\Program Files\Git\bin\bash.exe' failed to launch (exit code: 2)
I have already setup git. Git directory:
I had this issue with the 'start git-bash' extention in vscode. You just need to add the folder "C:\Program Files\Git\" to your path and restart vs code.
I reinstalled Git and all work well
Working Git Bash
If you have this issue, with the following error code:
'ExecutionPolicy', 'Bypass'" terminated with exit code: 2.'
What worked for me is I went into the settings.json file and removed the following line:
"terminal.integrated.shellArgs.windows": ["-ExecutionPolicy","Bypass"]
If Git Bash doesn't work you can try installing a Windows WSL2 such as Ubuntu 18.04 and use that instead of Git Bash.
Here is how you select a Windows WSL:
Check out this link if you need help installing WSL2 on Windows.
You can see a similar issue (with cmd, not bash) in Microsoft/vscode issue 62953.
Try with a portable version of Git bash (like PortableGit-2.20.0.rc1.windows.1-64-bit.7z.exe), uncompress in a custom folder (like C:\Git, instead of C:\Program Files\Git)
Sometimes antivirus software might cause that behaviour, since launchin a terminal involes a process creating another process.
So add an exception in your Antivirus for Visual Studio Code or stop all the antivirus related services --at your own risk--
First, check that you have Git Bash downloaded on your PC. If you already have it installed, then check you can access python program.
If not installed, please install directly from the following link: https://git-scm.com/download/win

Docker "Can't add file <path> to tar: readlink <path> The system cannot find the file specified"

I'm a beginner at docker trying to get it working on my Windows 10 machine using creator's update bash subsystem. My dockerfile builds fine on my mac, but when I try docker build from the same file on windows, I get errors like the following:
time="2017-08-28T14:44:36-07:00" level=error
msg="Can't add file \\\\?\\C:\\Users\\username\\Workspace\\...\\node_modules\\.bin\\nodemon
to tar: readlink \\\\?\\C:\\Users\\username\\Workspace\\...\\node_modules\\.bin\\nodemon:
The system cannot find the file specified."
This is printed out for all of my node_modules dependencies. My first question is: What is triggering this "add" operation for all of my node_modules? These error messages are printed out before the first line of my dockerfile is executed
Step 1/25 : FROM ubuntu:14.04
Second, does this issue have something to do with different paths in windows? To me, the weirdest part about the errors is the strange path \\\\?\\C:\\Users\\username. What is going on here with the excessive slashes and a question mark in the path?
Third, is it just me? Or does everyone encounter problems when using docker on windows bash subsystem?
NOTE: I've tried setting up the Docker Toolbox and running the quickstart terminal. I get the following error from running the quickstart terminal
Error with pre-create check:
"This computer is running Hyper-V. VirtualBox won't boot a 64bits VM when Hyper-V is activated. Either use Hyper-V as a driver, or disable the Hyper-V hypervisor. (To skip this check, use --virtualbox-no-vtx-check)"
Looks like something went wrong in step ´Checking if machine default exists
´... Press any key to continue...
So I've tried making sure hyper-v is enabled from this article here
NOTE 2: I've also made sure that my C drive is shared with my containers

Installing Heroku Toolbelt on Windows 10

I've been having some issues installing the Heroku toolbelt on Windows 10, 64-bit.
It's the first time I install Heroku. I downloaded it from https://toolbelt.heroku.com/windows.
After installing, I tried launching a new Git Bash and typing heroku login but what I got back was bash: heroku: command not found
Running the same command on Windows Powershell, what I got back was
'MYSQL' is not recognized as an internal or external command,
operable program or batch file.
'MYSQL' is not recognized as an internal or external command,
operable program or batch file.
Any suggestions? I thought that googling those lines would help, but I haven't found much.
I followed the recommendation from here, but now when typing heroku login on the Powershell, nothing happens. Nothing changes on the Git Bash.
I checked, and the Heroku folder was added to the PATH.
I thought I'd ask for some help before installing anything else.
Thank you!
bash: heroku: command not found
The error message is clear: Bash cannot find the heroku command, it's not on your PATH.
I checked, and the Heroku folder was added to the PATH.
It seems you didn't check it correctly.
Note that even if it looks correct in the PATH settings window,
Git Bash might have a different PATH configured.
To see the PATH in Git Bash, run:
echo $PATH
When debugging path issues,
it's best to first run heroku with the absolute path. For example if it's in C:\Program Files\Heroku\bin\heroku then you can run in Git Bash with:
/c/Program\ Files/Heroku/bin/heroku login
If this works (and it should),
then you can add it to PATH like this:
PATH="$PATH:/c/Program\ Files/Heroku/bin"
Note that Heroku will likely need other programs too on the PATH,
such as MySQL and Ruby.
Find their absolute paths,
and add there directories to PATH the same way as heroku itself in the above example.
If instead of Git Bash,
you want to work in CMD,
the procedure is the same,
but the syntax to print and set PATH is different:
echo %PATH%
set PATH="C:\Program Files\Heroku\bin;%PATH%"
In windows bash instead of this
PATH="$PATH:/c/Program\ Files/Heroku/bin"
use this
PATH="$PATH:/c/Program Files/Heroku/bin"
My working solution (for git-bash especially) is:
alias heroku='winpty `where heroku.cmd`'
stored in .bashrc in home user dir
and them
heroku
works as expected
If using bash from VSCode, I had to restart VSCode, after installing heroku. If not using VSCode, you probably need to restart your bash terminal, after installing heroku.
In Control Panel\All Control Panel Items\System (if you are using Windows), go to Advanced system settings, and there in Environment Variables, you'll find two lists, on the same window, viz. System variables, and User variables for your system. Make sure you add your path, viz. C:/Program Files/Heroku/bin, in both of these lists.
I know this is an old thread and just want to share my solution.
Edit .bashrc for git-bash
alias heroku='"C:\Program Files\Heroku\bin\heroku.cmd" $#'

msysgit error with hooks: "git error: cannot spawn .git/hooks/post-commit: No such file or directory"

I'm having trouble getting post-recieve and post-commit hooks to work correctly with msysgit (Windows 7 Pro/32 and Ultimate/64). For post-commit hook I get the above error if I commit from either git-bash or the console, but it works fine if I commit through git-gui. For a post-recieve hook, all three give the same error.
I'm thinking this is some sort of permission or path error, but don't really have any clue where to start here.
Add the SHEBANG to the first line of hook, like so:
#!/bin/sh
echo "executing post-commit"
exit 0
This had me stumped for a while as well and I saw that adding the shebang fixed it. In SVN world, while in *nix we have a "pre-commit" script and in Windows we had "pre-commit.bat" and SVN automatically picked up the bat file in Windows. Git doesn't seem to pick up a pre-commit.bat ( or any hook ) and adding the shebang to the hook file worked.
I'm using SourceTree and git LFS and had a similar issue: cannot spawn .git/hooks/pre-push.
The fix was to delete the pre-push file (opening it revealed it was badly corrupted) and restart SourceTree at which point it regenerates the pre-push file and everything is back to normal.
If you have the SHEBANG and it still fails, make sure you have <path_to_git>\bin set in your path environment variable.
You'll probably also have <path_to_git>\cmd if you installed it to work from the command-line.
This is an old question, but I've been fighting with this exact problem and this SO question popped up, so I thought it worth the effort to record what worked for me.
In short: I needed to run Apache as a regular user instead of Local System. This was on a legacy test VM I was playing with, so it was only running Windows XP, but it appears that at least on that platform (and possibly others), msysgit just doesn't work properly when running under the Local System account (presumably the root filesystem isn't mapped properly). As a result, no shebang line will work as git-http-backend simply can't execute any msysgit binaries (even with absolute Windows paths).
Switching Apache to run as a regular user account fixed this problem completely. Obviously you need to ensure that the user Apache is running as has permissions to read/write the git repositories, but beyond that, just make sure your shebang line is #!/bin/sh and everything should be copacetic.
Lastly, yeah, this is a big hammer. Ideally you'd be able to use something like suexec on Windows, but a quick googling doesn't indicate an obvious path forward, there. Of course, if anyone has any ideas, I'd be interested.
For now, this works for me, but it doesn't seem ideal.
Got this in a repo using LFS, got rid of it with git lfs update --force
If someone, like me run into a similar problem with accessing git repositories through apache, you should set the PATH in Apache config, like:
SetEnv PATH "c:/Program Files (x86)/Git/bin;"
Using tortoisegit and LFS, for me just had to remove the files inside of the .git/hooks folder.
If you are using Android studio, you can remove this error by un-check the checkbox "Run Git hooks":
For me, removing a comment line on front of the shebang line fixed the error. Oddly, the script ran fine from the shell, just errored out when run as a hook.

Resources