This repo is setup to build a Dev Container that can be transferred for use on an air-gapped network.
For a comprehensive discussion on creating your own air-gapped Dev Container image, refer to the Creating an Air-Gapped Dev Container document.
The following steps assume you are running Docker and have installed the devcontainers CLI.
-
Pre-build the
airgapped-dev
Dev Container by running:devcontainer build --workspace-folder .\src\ --image-name airgapped-dev:latest
-
Make sure you have pulled the
mssql/server:2022-latest
image for use after disconnecting the network adapter:docker pull mcr.microsoft.com/mssql/server:2022-latest
-
Open an administrative PowerShell terminal and run the Disable-AllAdapters script.
-
Press F1 to open the command palette and select Dev Containers: Reopen in Container.
-
You can install the
mssql
extension after the container is built by running the following:code --install-extension $HOME/mssql-ubuntu-x64.vsix
-
-
To cache the image for offline use, run:
# save the image docker save [image]:[tag] -o [image]-[tag].tar # gzip the image tarball tar -czvf [image]-[tag].tar.gz [image]-[tag].tar # example docker save airgapped-dev:latest -o airgapped-dev-latest.tar tar -czvf airgapped-dev-latest.tar.gz airgapped-dev-latest.tar
Initial builds of the image are in the range of ~4.5 GB. GZipping the image tarball will minimize the file size down to ~1.5 GB prior to transfer to the air-gapped environment.
After transfer, the image can be extracted with:
tar -xvf [image]-[tag].tar.gz
-
Download the version of Visual Studio Code that corresponds to the commit in
vscode-server.sh
.You can download by commit by using the following endpoint:
https://code.visualstudio.com/sha/download?os=[os-preference]&commit=[commit]
- Windows x64 System Installer: https://code.visualstudio.com/sha/download?os=win32-x64&commit=863d2581ecda6849923a2118d93a088b0745d9d6
- Windows x64 User Installer: https://code.visualstudio.com/sha/download?os=win32-x64&commit=863d2581ecda6849923a2118d93a088b0745d9d6
To simplify this process, ensure the image is updated with the latest version of VS Code Server.
The script that generates the VS Code Server infrastructure on the Dev Container image relies on:
-
The commit string for the release of VS Code the server is being generated against.
-
The version of the VS Code SQL Server extension.
To ensure that you have the latest version of these values, make sure your local VS Code instance is up to date then run the Update-Source.ps1
script out of the scripts
directory.
Once you have the cached Dev Container image, you can build out development environments centered around that Dev Container.
The root .devcontainer
directory provides a great example of this. It assumes that you will be developing with SQL Server 2022, so it uses Docker Compose to host the official SQL Server 2022 image in a container alongside the Dev Container.
The devcontainer.json
file specifies:
- The name of the Dev Container image
- Docker Compose metadata such as the docker compose file, the service that represents the Dev Container image, and the workspace folder.
- Environment variables to set on the Dev Container image.
- Forwarded ports and port attributes. In this case
1433
is configured for SQL Server. - VS Code extension settings to configure in the Dev Container. In this case, the connection to SQL Server is configured for the SQL Server extension.
If you want to support an ASP.NET Core project, such as a Web API, that supports both local and Dev Container development, you can isolate a Container
environment configuration.
In [Project]/Properties/launchSettings.json
:
"profiles": {
"development": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"container": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Container"
}
}
}
To connect to the container instance of SQL Server, create an appsettings.Container.json
file, replacing the key and database name with your relevant values:
{
"ConnectionStrings": {
"[key]": "Server=localhost,1433;Encrypt=Mandatory;TrustServerCertificate=True;User=sa;Password=P@ssw0rd;Database=[database-name]"
}
}
The container
environment can be run with:
dotnet run --launch-profile "container"
which can be aliased to a VS Code task.