Search code examples
windowscurldocker-composedockerfileline-endings

Why is CURL not working in my Dockerfile when running docker compose build?


I work on a Windows machine, and I code mainly in Visual Studio Code. I am writing a Dockerfile and using a docker compose yml file with it, the image is on the latest ubuntu release. What I was trying to do was to use curl to get the latest github release for a public repo.

My problem was that when trying to run docker compose -f compose.yml build --pull I kept getting this error: **curl: (3) URL using bad/illegal format or missing URL**

I did it in the ways listed in this github issue: https://gist.github.com/gvenzl/1386755861fb42db492276d3864a378c

To try to fix the error, I followed comments from the above github link, as well as from here: Can't run Curl command inside my Docker Container, which included

  • adding double quotes,
  • making it into a single line with piping
  • using <<EOF format for the RUN command
  • switching to escape characters and "&&" for the RUN command
  • moving around my apt-get install -y curl command

but nothing was working because every time I would get the same error. I had tested each command with a shell script on Windows Subsystem for Linux (WSL), and they worked fine there. I was able to get the correct string using curl and sed (I printed it out to test that bit), and I was able to correctly pull the zip file I wanted. So, I had thought it was something wrong with docker compose and curl, but I'd found others who just said to fix that, they installed curl, which I had already done.


Solution

  • It was the line endings, or the end of line sequence. Since I'm on a windows machine, it automatically assigns CLRF line endings, which is \r\n. Docker wants you to use LF line endings, or \n. I changed this in my Dockerfile on VSCode by clicking the "CRLF" button on the bottom right of my editor view, and switching it to LF. snip of the bottom right of VSCode's editor view

    I read about it here LF will be replaced by CRLF in git - What is that and is it important?, in a similar issue I had when pushing to Github, and having this warning pop up:

    The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in .