NET 6 and SQL Server development environment into a Docker container using Visual Studio Code’s Remote Development today. Although it went smoothly with the documentation, the problem arose after the project was versioned. I think the point of this article is that in today’s containerized, cross-platform era, line breaks actually have to be confronted, or else you’ll be at a loss for what to do.
Experience the feeling of developing in containers
-
Install the Docker Desktop and Remote Development extensions first.
-
Create the basic ASP.NET Core 6 project and open it with Visual Studio Code first.
-
Press
F1>Remote-Containers: Add Development Container Configuration Files -
Select a Dev Container template first:
C# (.NET) and MS SQL
-
Select .NET version:
6.0-focal
-
Select Node.js version:
none
-
Select the tool to be used in the container: Here we do not select it first, we can just press
OKto finish the setting
That’s all set! π
-
Next, let’s do Git version control.
To do this, I’ll start by adding a .NET-specific
.gitignorefile.1dotnet new gitignoreThe following is the final version, basically each file you can click on to see.

Establish version control.
-
Run
F1>Remote-Containers: Reopen in Containerto start automatically
Behind this action, all the required container images are automatically created, and then automatically started, the container environment is automatically initialized (installing the necessary development tools), the necessary network connection port forwarding is turned on (Port Forwarding), and then you can smoothly develop, test, and execute in the Container container connected to Visual Studio Code.
Experience the problem after version control
Since the .devcontainer/Dockerfile file in the project is responsible for building all the environments in the Dev Container development container, it contains SQL-related tools such as sqlcmd, bcp, sqlpackage, etc.
The contents of this .devcontainer/Dockerfile are as follows
|
|
You can find that he has copied mssql/installSQLtools.sh to the container, the point is that the Dev Container provided by Microsoft is based on Ubuntu 20.04.4 LTS as the main operating system, and when running this command, it will require all Shell Scripts to be executed with LF as the main line break character, so the common Windows CRLF line break character is not available, and the process of building container image will be wrong!
Let’s take a look at the process of how this error occurred.
-
The container does not contain the project source code.
Microsoft’s Dev Container uses volumn mapping to mount source code into the container, so you only have the “project execution environment” in the container!
-
Judging
~/.gitconfigsettingsWhen we first create a container image, it automatically copies the Windows local
~/.gitconfigdomain-wide configuration file to the~/.gitconfigcontainer environment, so basically the Git settings underUbuntu 20.04.4 LTSare exactly the same as Windows. But Windows has a default value ofcore.autocrlf=true, which means that when all files are checked out, all text files are automatically treated as line feeds withCRLF, but that’s a big problem! -
Retrieve the source code
Since the
.devcontainer/mssql/installSQLtools.shfile was initially saved asLF, it will be automatically converted toCRLFnewlines as soon as the source code is retrieved, so we can expect the.devcontainer/Dockerfileto have Error!You can try removing the entire
.devcontainerand retrieving the file withgit reset --hard. -
Run
F1>Remote-Containers: Reopen Folder Locallyto go back to Windows and open this project
-
Run
F1>Rebuild Without Cache and Reopen in ContainerRebuild the container image of the Dev Container
At this point you will see the error message.
|
|

If you look at the Terminal, you can see the relatively detailed error message.

|
|
When the problem occurred, it wasn’t very understandable at first, but you should now know very well that it was the line break that caused the error!
The right solution
The most standard solution to this problem is as follows.
-
Run
F1>Remote-Containers: Reopen Folder Locallyto go back to Windows and open this project -
Create a
.gitattributesfile under the.devcontainer/mssql/directory and add the following.1*.sh text eol=lfThis will ensure that all
*.shfiles in that directory will always useLFas a newline character when Git pulls them out. -
Delete the
.devcontainer/mssql/*.shfile, and usegit checkoutorgit reset --hardto retrieve the file. -
Run
F1>Rebuild Without Cache and Reopen in Containerto rebuild the container image of Dev Container
You should be able to build the container again this time! π
Conclusion
This problem is actually not likely to occur in macOS or Linux, only Windows users will encounter this situation, which makes me wonder if no Microsoft engineers are using Windows anymore ah? π
However, I still think that as long as you are a Windows-loving developer like me, you should understand the difference between CRLF and LF, so that you will step on fewer mines in the process of containerization in the future.