Skip to content

Commit 7eae2b1

Browse files
committed
Updated changes for v14 and v16
1 parent ede5593 commit 7eae2b1

File tree

2 files changed

+203
-69
lines changed

2 files changed

+203
-69
lines changed
Lines changed: 102 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,141 @@
11
---
2-
description: "Running Umbraco on docker locally using docker compose"
2+
description: Running Umbraco on docker locally using docker compose
33
---
44

55
# Running Umbraco in Docker using Docker Compose
66

7-
To aid in developing Umbraco with additional services, the templates can provide the requisite files to run Umbraco with an SQL Server database in Docker. This setup is designed to be used for local development, and not for production.
7+
This article shows how to run Umbraco locally in Docker using Docker Compose. You can use either SQL Server or SQLite for development.
8+
9+
{% hint style="info" %}
10+
This setup is intended for local development only. It is not recommended for production environments.
11+
{% endhint %}
812

913
## Prerequisites
1014

11-
Before you can run Umbraco in Docker, you need to have the following installed:
12-
* Version 14.3.0 or higher of the Umbraco Templates
15+
Before you can run Umbraco in Docker, make sure the following are installed:
16+
17+
* .NET SDK with Umbraco Templates v14.3.0 or higher
1318
* Docker Desktop
1419

1520
## Installing
1621

17-
Installing Umbraco with the Docker file and Docker Compose file is a two-step process.
22+
To install Umbraco using the provided Dockerfile and Docker Compose setup, follow these steps:
23+
24+
### Option 1: Using SQL Server
1825

19-
1. Create a folder to hold your project and enter that folder.
26+
1. Create a folder and navigate into it:
2027

2128
```bash
2229
mkdir MyDockerProject
2330
cd MyDockerProject
2431
```
25-
2. Create your Umbraco project using the Umbraco Templates, and remember to use the `--add-docker` flag to include the Docker files.
2632

33+
2. Create a new Umbraco project with Docker support:
2734

28-
Conventionally this is named the same as the folder, but it is not a requirement.
29-
30-
```bash
35+
```csharp
3136
dotnet new umbraco -n MyDockerProject --add-docker
3237
```
3338

34-
Now we need to add some additional files to make docker compose work. We can do this using the umbraco-compose template, passing the project name we specified earlier to the -P parameter:
39+
3. Add Docker Compose files:
3540

36-
```bash
41+
```csharp
3742
dotnet new umbraco-compose -P "MyDockerProject"
3843
```
3944

40-
The `-P` flag is required to specify the correct paths in the docker-compose file. The project is now ready to run with docker compose.
45+
The `-P` flag is required to specify the correct paths in the docker-compose file. The project is now ready to run with Docker Compose.
4146

42-
The final folder structure looks like this:
47+
The folder structure should now look like this:
4348

44-
* MyDockerProject
45-
* MyDockerProject
46-
* Typical project files
47-
* DockerFile
48-
* `.dockerignore`
49-
* `.env`
50-
* Database
51-
* DockerFile
52-
* `healthcheck.sh`
53-
* `setup.sql`
54-
* `startup.sh`
55-
* `docker-compose.yml`
49+
* MyDockerProject/
50+
* Database/
51+
* Dockerfile
52+
* healthcheck.sh
53+
* setup.sql
54+
* startup.sh
55+
* MyDockerProject/
56+
* Your project files
57+
* Dockerfile
58+
* .dockerignore
59+
* .env
60+
* docker-compose.yml
5661

5762
The project now includes docker files for both Umbraco and the SQL server database.
5863

5964
It also includes additional scripts to launch and configure the database and a `.env` file with the database password.
6065

61-
## Running
66+
4. Run the following command from the root folder (where `docker-compose.yml` is located):
67+
68+
```bash
69+
docker compose up
70+
```
71+
72+
5. Access the site at `http://localhost:44372`.
73+
74+
### Option 2: Using SQLite
75+
76+
1. Create a new folder and navigate into it:
77+
78+
```bash
79+
mkdir MyDockerSqliteProject
80+
cd MyDockerSqliteProject
81+
```
82+
83+
2. Create a new Umbraco project:
84+
85+
```csharp
86+
dotnet new umbraco -n MyDockerSqliteProject
87+
```
88+
89+
3. Add a Dockerfile
90+
91+
{% code overflow="wrap" fullWidth="false" %}
92+
```bash
93+
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
94+
WORKDIR /app
95+
EXPOSE 8080
96+
97+
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
98+
ARG BUILD_CONFIGURATION=Release
99+
WORKDIR /src
100+
COPY ["MyDockerSqliteProject/MyDockerSqliteProject.csproj", "MyDockerSqliteProject/"]
101+
RUN dotnet restore "MyDockerSqliteProject/MyDockerSqliteProject.csproj"
102+
COPY . .
103+
WORKDIR "/src/MyDockerSqliteProject"
104+
RUN dotnet build "MyDockerSqliteProject.csproj" -c $BUILD_CONFIGURATION -o /app/build
105+
106+
FROM build AS publish
107+
RUN dotnet publish "MyDockerSqliteProject.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
108+
109+
FROM base AS final
110+
WORKDIR /app
111+
COPY --from=publish /app/publish .
112+
ENTRYPOINT ["dotnet", "MyDockerSqliteProject.dll"]
113+
```
114+
{% endcode %}
115+
116+
{% hint style="info" %}
117+
To speed up the build process, add a `.dockerignore` file to exclude unnecessary folders like `.git`, `bin`, and `obj`.
118+
{% endhint %}
119+
120+
4. Build the container:
121+
122+
```bash
123+
docker build -t umbraco-sqlite .
124+
```
125+
126+
5. Run the container:
62127

63-
To run the project use the `docker compose up` command in the root of the project files where the `docker-compose.yml` is.
128+
```bash
129+
docker run -p 8080:8080 umbraco-sqlite
130+
```
64131

65-
This command will build both the Umbraco and SQL Server images and launch them in the correct order. When the site is booted, access it in your browser on `http://localhost:44372/`.
132+
6. Access the site at `http://localhost:8080`.
66133

67-
### Useful commands
134+
## Useful Commands
68135

69136
There are some useful commands you can use to manage the docker containers:
70137

71-
* `docker compose down --volumes`: Delete your containers and the volumes they use. This is useful if you want to start from scratch.
138+
* `docker compose down --volumes`: Deletes containers and the volumes they use. This is useful if you want to start from scratch.
72139

73140
{% hint style="warning" %}
74141
Be careful with this command, as it deletes your database and all data in it.
@@ -77,7 +144,7 @@ Be careful with this command, as it deletes your database and all data in it.
77144
* `docker compose up --build`: Rebuild the images and start the containers. This is useful if you have made changes to the project and want to see them reflected on the running site.
78145
* `docker compose watch`: Start the containers and watch the default models folder. This means that if the project uses a source-code models builder the images are automatically rebuilt and restarts when you change the models.
79146

80-
## Details
147+
## Bind Mounts (SQL Server setup)
81148

82149
The docker compose file uses bind mounts for the following folders:
83150

@@ -91,10 +158,10 @@ This is not meant to be used in production.
91158

92159
For local development, however, this means that the files necessary for development are available from outside the container in your IDE. This allows development even though the project is running in docker.
93160

94-
## Template options
161+
## Template Options (SQL Server only)
95162

96-
The `umbraco-compose` template has a few options that can be used to customize the setup:
163+
The `umbraco-compose` template supports:
97164

98165
* `-P` or `--project-name`: The name of the project. This is required and used to set the correct paths in the docker-compose file.
99-
* `-dbpw` or `--DatabasePasswor`: Used to specify the database password. This is stored in the `.env` file and defaults to: `Password1234`.
166+
* `-dbpw` or `--DatabasePassword`: Used to specify the database password. This is stored in the `.env` file and defaults to: `Password1234`.
100167
* `-p` or `--Port`: Used to specify the port the site will run on. Defaults to `44372`.

16/umbraco-cms/fundamentals/setup/install/running-umbraco-on-docker-locally.md

Lines changed: 101 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,141 @@
11
---
2-
description: "Running Umbraco on docker locally using docker compose"
2+
description: Running Umbraco on docker locally using docker compose
33
---
44

55
# Running Umbraco in Docker using Docker Compose
66

7-
To aid in developing Umbraco with additional services, the templates can provide the requisite files to run Umbraco with an SQL Server database in Docker. This setup is designed to be used for local development, and not for production.
7+
This article shows how to run Umbraco locally in Docker using Docker Compose. You can use either SQL Server or SQLite for development.
8+
9+
{% hint style="info" %}
10+
This setup is intended for local development only. It is not recommended for production environments.
11+
{% endhint %}
812

913
## Prerequisites
1014

11-
Before you can run Umbraco in Docker, you need to have the following installed:
12-
* Version 14.3.0 or higher of the Umbraco Templates
15+
Before you can run Umbraco in Docker, make sure the following are installed:
16+
17+
* .NET SDK with Umbraco Templates v16 or higher
1318
* Docker Desktop
1419

1520
## Installing
1621

17-
Installing Umbraco with the Docker file and Docker Compose file is a two-step process.
22+
To install Umbraco using the provided Dockerfile and Docker Compose setup, follow these steps:
23+
24+
### Option 1: Using SQL Server
1825

19-
1. Create a folder to hold your project and enter that folder.
26+
1. Create a folder and navigate into it:
2027

2128
```bash
2229
mkdir MyDockerProject
2330
cd MyDockerProject
2431
```
25-
2. Create your Umbraco project using the Umbraco Templates, and remember to use the `--add-docker` flag to include the Docker files.
2632

33+
2. Create a new Umbraco project with Docker support:
2734

28-
Conventionally this is named the same as the folder, but it is not a requirement.
29-
30-
```bash
35+
```csharp
3136
dotnet new umbraco -n MyDockerProject --add-docker
3237
```
3338

34-
Now we need to add some additional files to make docker compose work. We can do this using the umbraco-compose template, passing the project name we specified earlier to the -P parameter:
39+
3. Add Docker Compose files:
3540

36-
```bash
41+
```csharp
3742
dotnet new umbraco-compose -P "MyDockerProject"
3843
```
3944

40-
The `-P` flag is required to specify the correct paths in the docker-compose file. The project is now ready to run with docker compose.
45+
The `-P` flag is required to specify the correct paths in the docker-compose file. The project is now ready to run with Docker Compose.
4146

42-
The final folder structure looks like this:
47+
The folder structure should now look like this:
4348

44-
* MyDockerProject
45-
* MyDockerProject
46-
* Typical project files
47-
* DockerFile
48-
* `.dockerignore`
49-
* `.env`
50-
* Database
51-
* DockerFile
52-
* `healthcheck.sh`
53-
* `setup.sql`
54-
* `startup.sh`
55-
* `docker-compose.yml`
49+
* MyDockerProject/
50+
* Database/
51+
* Dockerfile
52+
* healthcheck.sh
53+
* setup.sql
54+
* startup.sh
55+
* MyDockerProject/
56+
* Your project files
57+
* Dockerfile
58+
* .dockerignore
59+
* .env
60+
* docker-compose.yml
5661

5762
The project now includes docker files for both Umbraco and the SQL server database.
5863

5964
It also includes additional scripts to launch and configure the database and a `.env` file with the database password.
6065

61-
## Running
66+
4. Run the following command from the root folder (where `docker-compose.yml` is located):
67+
68+
```bash
69+
docker compose up
70+
```
71+
72+
5. Access the site at `http://localhost:44372`.
73+
74+
### Option 2: Using SQLite
75+
76+
1. Create a new folder and navigate into it:
77+
78+
```bash
79+
mkdir MyDockerSqliteProject
80+
cd MyDockerSqliteProject
81+
```
82+
83+
2. Create a new Umbraco project:
84+
85+
```csharp
86+
dotnet new umbraco -n MyDockerSqliteProject
87+
```
88+
89+
3. Add a Dockerfile
90+
91+
{% code overflow="wrap" fullWidth="false" %}
92+
```bash
93+
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
94+
WORKDIR /app
95+
EXPOSE 8080
96+
97+
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
98+
ARG BUILD_CONFIGURATION=Release
99+
WORKDIR /src
100+
COPY ["MyDockerSqliteProject/MyDockerSqliteProject.csproj", "MyDockerSqliteProject/"]
101+
RUN dotnet restore "MyDockerSqliteProject/MyDockerSqliteProject.csproj"
102+
COPY . .
103+
WORKDIR "/src/MyDockerSqliteProject"
104+
RUN dotnet build "MyDockerSqliteProject.csproj" -c $BUILD_CONFIGURATION -o /app/build
105+
106+
FROM build AS publish
107+
RUN dotnet publish "MyDockerSqliteProject.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
108+
109+
FROM base AS final
110+
WORKDIR /app
111+
COPY --from=publish /app/publish .
112+
ENTRYPOINT ["dotnet", "MyDockerSqliteProject.dll"]
113+
```
114+
{% endcode %}
115+
116+
{% hint style="info" %}
117+
To speed up the build process, add a `.dockerignore` file to exclude unnecessary folders like `.git`, `bin`, and `obj`.
118+
{% endhint %}
119+
120+
4. Build the container:
121+
122+
```bash
123+
docker build -t umbraco-sqlite .
124+
```
125+
126+
5. Run the container:
62127

63-
To run the project use the `docker compose up` command in the root of the project files where the `docker-compose.yml` is.
128+
```bash
129+
docker run -p 8080:8080 umbraco-sqlite
130+
```
64131

65-
This command will build both the Umbraco and SQL Server images and launch them in the correct order. When the site is booted, access it in your browser on `http://localhost:44372/`.
132+
6. Access the site at `http://localhost:8080`.
66133

67-
### Useful commands
134+
## Useful Commands
68135

69136
There are some useful commands you can use to manage the docker containers:
70137

71-
* `docker compose down --volumes`: Delete your containers and the volumes they use. This is useful if you want to start from scratch.
138+
* `docker compose down --volumes`: Deletes containers and the volumes they use. This is useful if you want to start from scratch.
72139

73140
{% hint style="warning" %}
74141
Be careful with this command, as it deletes your database and all data in it.
@@ -77,7 +144,7 @@ Be careful with this command, as it deletes your database and all data in it.
77144
* `docker compose up --build`: Rebuild the images and start the containers. This is useful if you have made changes to the project and want to see them reflected on the running site.
78145
* `docker compose watch`: Start the containers and watch the default models folder. This means that if the project uses a source-code models builder the images are automatically rebuilt and restarts when you change the models.
79146

80-
## Details
147+
## Bind Mounts (SQL Server setup)
81148

82149
The docker compose file uses bind mounts for the following folders:
83150

@@ -91,9 +158,9 @@ This is not meant to be used in production.
91158

92159
For local development, however, this means that the files necessary for development are available from outside the container in your IDE. This allows development even though the project is running in docker.
93160

94-
## Template options
161+
## Template Options (SQL Server only)
95162

96-
The `umbraco-compose` template has a few options that can be used to customize the setup:
163+
The `umbraco-compose` template supports:
97164

98165
* `-P` or `--project-name`: The name of the project. This is required and used to set the correct paths in the docker-compose file.
99166
* `-dbpw` or `--DatabasePassword`: Used to specify the database password. This is stored in the `.env` file and defaults to: `Password1234`.

0 commit comments

Comments
 (0)