A development container is a running Docker container with a well-defined tool/runtime stack and its prerequisites. You can try out development containers with GitHub Codespaces or Visual Studio Code Remote - Containers.
This is a sample project that lets you try out either option in a few easy steps. We have a variety of other vscode-remote-try-* sample projects, too.
Note: If you already have a Codespace or dev container, you can jump to the Things to try section.
Follow these steps to open this sample in a Codespaces:
- Click the Code drop-down menu and select the Codespaces tab.
- Click on Create codespaces on main at the bottom of the pane.
For more info, check out the GitHub documentation.
If you already have VS Code and Docker installed, you can click the badge above or here to get started. Clicking these links will cause VS Code to automatically install the Dev Containers extension if needed, clone the source code into a container volume, and spin up a dev container for use.
Follow these steps to open this sample in a container using the VS Code Dev Containers extension:
-
If this is your first time using a development container, please ensure your system meets the pre-reqs (i.e. have Docker installed) in the getting started steps.
-
To use this repository, you can either open the repository in an isolated Docker volume:
- Press F1 and select the Dev Containers: Try a Sample... command.
- Choose the ".NET Core" sample, wait for the container to start, and try things out!
Note: Under the hood, this will use the Dev Containers: Clone Repository in Container Volume... command to clone the source code in a Docker volume instead of the local filesystem. Volumes are the preferred mechanism for persisting container data.
Or open a locally cloned copy of the code:
- Clone this repository to your local filesystem.
- Press F1 and select the Dev Containers: Open Folder in Container... command.
- Select the cloned copy of this folder, wait for the container to start, and try things out!
This template creates two containers, one for the Dev Container that includes .NET and Data API builder and one for Microsoft SQL Server. You will be connected to the Ubuntu, and from within that container the MS SQL container will be available on localhost
port 1433. The Data API builder container also includes supporting scripts in the .devcontainer/sql
folder used to configure the Library
sample database.
The SQL container is deployed from the latest developer edition of Microsoft SQL 2022. The database(s) are made available directly in the Codespace/VS Code through the MSSQL extension with a connection labeled "LocalDev". The default sa
user password is set to P@ssw0rd!
. The default SQL port is mapped to port 1433
in .devcontainer/docker-compose.yml
.
Data API builder is a .NET Core application that provides a RESTful API for interacting with the SQL server. This sample repository includes a preconfigured database, that is used by DAB to create the REST and GraphQL endpoints. If you wan to run some manual tests, you can use the dab_http_request.sh
file included in the scripts
folder. This sh
file includes multiple http request calls you can to understand how the Data API builder to interact with the SQL server.
We have added several tasks to this repository to help with common actions. You can access these tasks by opening the Command Palette in VS Code. Here's how:
- Press F1 or Ctrl+Shift+P to open the Command Palette.
- Type "Run Task" and select "Tasks: Run Task".
- Choose the task you want to run from the list.
This task starts the DAB server with the specified configuration file. It runs the command dab start --config=dab.config.json --no-https-redirect
in the dab
directory of your workspace.
This task builds the SQL Database project. It runs the command dotnet build
in the database/Library
directory of your workspace.
This task opens the verifyDatabase.sql
file in your workspace and executes the SQL query in it. It uses the ms-mssql.mssql
extension to execute the query. This task is part of the build group and is the default task that runs when you run the build task group.
To change the sa
user password, change the value in .devcontainer/docker-compose.yml
and .devcontainer/devcontainer.json
.
By default, a demo database is created titled "Library". To add additional database objects or data through T-SQL during Codespace configuration, edit the file .devcontainer/sql/library.azure-sql.sql
or place additional .sql
files in the .devcontainer/mssql/
folder. Large numbers of scripts may take a few minutes following container creation to complete, even when the SQL server is available the database(s) may not be available yet.
You can also the SQL Database Projects extension to deploy the database schema. The Library.sqlproj
project is located in the database/Library
folder can be build using the Build SQL Database project
task. The verifyDatabase.sql
file in the database/Library
folder can be used to verify the database schema.
Alternatively, .dacpac files placed in the ./bin/Debug
folder will be published as databases in the container during Dev Container configuration. SqlPackage is used to deploy a database schema from a data-tier application file (dacpac), allowing you to bring your application's database structures into the dev container easily. The publish process may take a few minutes following container creation to complete, even when the server is available the database(s) may not be available yet.
You can add other services to your .devcontainer/docker-compose.yml
file as described in Docker's documentation. However, if you want anything running in this service to be available in the container on localhost, or want to forward the service locally, be sure to add this line to the service config:
# Runs the service on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:db
By default, web frameworks and tools often only listen to localhost inside the container. As a result, we recommend using the forwardPorts
property to make these ports available locally.
"forwardPorts": [9000]
The ports
property in docker-compose.yml
publishes rather than forwards the port. This will not work in a cloud environment like Codespaces and applications need to listen to *
or 0.0.0.0
for the application to be accessible externally. Fortunately the forwardPorts
property does not have this limitation.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.