Backend Development 15 min read

Developing ASP.NET Core Applications on macOS with VS Code, Docker, and MySQL

This tutorial explains how to set up a macOS development environment with Visual Studio Code and .NET Core, create an ASP.NET Core web application, configure a MySQL database using Docker containers, and package the app for production deployment with Docker Compose.

DevOps
DevOps
DevOps
Developing ASP.NET Core Applications on macOS with VS Code, Docker, and MySQL

In this guide we show how to develop an ASP.NET Core application on macOS using Visual Studio Code as the editor, Docker for containerized development, and MySQL as the backend database.

Preparing the development environment

Install the following tools:

1. Visual Studio Code and .NET Core – a free, open‑source, cross‑platform code editor with extensions for C# development.

2. Node.js and npm – to install front‑end tools such as Bower, Gulp and Grunt.

npm install bower gulp grunt-cli -g

3. Yeoman and the ASP.NET generator – for scaffolding project templates.

npm install yo -g
npm install generator-aspnet -g

4. Docker for Mac – provides a Docker engine on macOS.

After installing these tools the development environment is ready.

Creating the ASP.NET Core web app

Create a project directory and use Yeoman to generate a web application template:

mkdir aspnet-mysql && cd aspnet-mysql && mkdir src
cd src
yo aspnet

Select "Web Application [without Membership and Authorization]" and choose Bootstrap as the front‑end framework.

Restore NuGet packages and open the project in VS Code:

cd aspnet-mysql
dotnet restore
code .

VS Code will generate .vscode/launch.json and .vscode/task.json for debugging.

Running MySQL in a Docker container

Start a MySQL container to use as the development database:

docker run --name mysql-dev -e MYSQL_ROOT_PASSWORD=P2ssw0rd -e MYSQL_DATABASE=ef -p 3306:3306 -d mysql

The container exposes port 3306, allowing tools such as MySQL Workbench to connect.

Configuring ASP.NET Core to use MySQL

Add the Pomelo MySQL provider to project.json :

"Pomelo.EntityFrameworkCore.MySql": "1.0.0-prerelease-20160726"

Create a nuget.config with the Pomelo feed and restore packages:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="NuGet official package source" value="https://nuget.org/api/v2/" />
    <add key="PomeloMysql" value="https://www.myget.org/F/pomelo/api/v2/"/>
  </packageSources>
</configuration>
dotnet restore --configfile nuget.config

In Startup.cs register the MySQL context:

services.AddDbContext<MyContext>(options =>
    options.UseMySql(Configuration.GetConnectionString("Mysql")));
await SampleData.InitDB(app.ApplicationServices);

Add a connection string to appsettings.json :

"ConnectionStrings": {
  "DefaultConnection": "Data Source=aspnetweb01.db",
  "Mysql": "Server={docker machine ip};database=ef;uid=root;pwd=P2ssw0rd;"
}

Packaging the application with Docker

The generated project already contains a Dockerfile . Its content is:

FROM microsoft/dotnet:latest
COPY . /app
WORKDIR /app
RUN ["dotnet", "restore", "--configfile", "nuget.config"]
RUN ["dotnet", "build"]
EXPOSE 5000/tcp
ENTRYPOINT ["dotnet", "run", "--server.urls", "http://0.0.0.0:5000"]

Build the image and run the container:

docker build -t ups216/aspnet-mysql .
docker run --name aspnet-mysql-dev -p 5000:5000 ups216/aspnet-mysql

Production deployment with docker‑compose

Create appsettings.Production.json that points to a MySQL service named db :

{
  "ConnectionStrings": {
    "DefaultConnection": "Data Source=aspnetweb01.db",
    "Mysql": "Server=db;database=ef;uid=ef;pwd=P2ssw0rd;"
  },
  "Logging": { "IncludeScopes": false, "LogLevel": { "Default": "Debug", "System": "Information", "Microsoft": "Information" } }
}

Define docker-compose.yml to run both the database and the web app:

version: '2'
services:
  db:
    image: mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: P2ssw0rd
      MYSQL_DATABASE: ef
      MYSQL_USER: ef
      MYSQL_PASSWORD: P2ssw0rd
  web:
    build: .
    depends_on:
      - db
    links:
      - db
    ports:
      - "5000:5000"
    restart: always
    environment:
      ASPNETCORE_ENVIRONMENT: Production

Start the whole stack with a single command:

docker-compose up

All source files are available on GitHub at https://github.com/ups216/aspnet-mysql/ .

DockerBackend DevelopmentDevOpsMySQLmacOSVS CodeASP.NET Core
DevOps
Written by

DevOps

Share premium content and events on trends, applications, and practices in development efficiency, AI and related technologies. The IDCF International DevOps Coach Federation trains end‑to‑end development‑efficiency talent, linking high‑performance organizations and individuals to achieve excellence.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.