An example of a .NET REST API (with database)
- Prerequisites
- Environment
2.1. Docker
2.2. .NET Core SDK - Usage
- macOS, Linux or Windows 10
- 🐳 Docker
- Compatible IDE or editor
- Visual Studio
- Visual Studio Code
- Rider
- hell, even Vim if you want...
The official Docker documentation is simply wonderful. Follow the steps, and everything should be as smooth as possible.
⚠ Make sure to read the "OS requirements" part first. Not all Linux distrubtions are properly supported. Also, LTS versions are usually highly recommanded.
Once ready, Docker Compose is the next step. Please note that even if there's lot of differents installation options, the Python package is often the preferred option (for its ease-of-use and easy upgradability):
pip3 install docker-compose
⚠ This command might conflit with your existing Python installation. In that case, other installation ways should be preferred.
Use the following commands to make sure everything is correctly installed:
docker --version
docker-compose --version
After Docker and Docker Compose, a Windows installation might require a little bit more of work: using the Windows Subsystem for Linux.
The Windows Subsystem for Linux lets developers run a GNU/Linux environment -- including most command-line tools, utilities, and applications -- directly on Windows, unmodified, without the overhead of a virtual machine.
Use the previous link to get started with this truly life-changing Windows feature.
Then, follow these few configuration steps to connect your new Linux terminal to Docker:
- Expose the Docker deamon without TLS:
- Share your disk drives to Docker:
- Install Docker on your Linux subsystem (see 2.1. Docker)
- Connect your Linux installation to your Windows Docker instance:
export DOCKER_HOST=tcp://localhost:2375
# To avoid entering this line at every shell launch, add it to your .profile, .bashrc or your preferred shell startup configuration.
- Finally, create the Linux file
/etc/wsl.conf
(as sudo), and enter this content:
[automount]
root = /
options = "metadata"
This will change your Windows disk mount point from /mnt/<disk_letter>
to /<disk_letter>
(i.e: /mnt/c
to /c
).
Several system reboots might be required for some steps.
The official .NET Core documentation is also very detailled. Use the radio menu below the title to choose your OS.
Use the following commands to make sure everything is correctly installed:
dotnet --version
The repository is Docker-based: from a clean installation, simply run docker-compose up
to build and run the sample API.
Default port is 8080
.
Docker compose supports various options and arguments.
See the compose documentation for more.