Skip to content

Commit 39da2fc

Browse files
authored
Merge pull request #7072 from umbraco/docker
Updated the article to include SQLite setup as well
2 parents 1bf1e36 + f99612b commit 39da2fc

File tree

1 file changed

+96
-31
lines changed

1 file changed

+96
-31
lines changed

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

Lines changed: 96 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,71 +4,136 @@ description: "Running Umbraco on docker locally using docker compose"
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 v15 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

27-
28-
Conventionally this is named the same as the folder, but it is not a requirement.
33+
2. Create a new Umbraco project with Docker support:
2934

3035
```bash
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

3641
```bash
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+
```
6282

63-
To run the project use the `docker compose up` command in the root of the project files where the `docker-compose.yml` is.
83+
2. Create a new Umbraco project:
84+
85+
```bash
86+
dotnet new umbraco -n MyDockerSqliteProject
87+
```
88+
89+
3. Add a Dockerfile
90+
91+
```bash
92+
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
93+
WORKDIR /app
94+
EXPOSE 8080
95+
96+
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
97+
ARG BUILD_CONFIGURATION=Release
98+
WORKDIR /src
99+
COPY ["MyDockerSqliteProject/MyDockerSqliteProject.csproj", "MyDockerSqliteProject/"]
100+
RUN dotnet restore "MyDockerSqliteProject/MyDockerSqliteProject.csproj"
101+
COPY . .
102+
WORKDIR "/src/MyDockerSqliteProject"
103+
RUN dotnet build "MyDockerSqliteProject.csproj" -c $BUILD_CONFIGURATION -o /app/build
104+
105+
FROM build AS publish
106+
RUN dotnet publish "MyDockerSqliteProject.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
107+
108+
FROM base AS final
109+
WORKDIR /app
110+
COPY --from=publish /app/publish .
111+
ENTRYPOINT ["dotnet", "MyDockerSqliteProject.dll"]
112+
```
113+
114+
{% hint style="info" %}
115+
To speed up the build process, add a `.dockerignore` file to exclude unnecessary folders like `.git`, `bin`, and `obj`.
116+
{% endhint %}
117+
118+
4. Build the container:
119+
120+
```bash
121+
docker build -t umbraco-sqlite .
122+
```
123+
124+
5. Run the container:
125+
126+
```bash
127+
docker run -p 8080:8080 umbraco-sqlite
128+
```
64129

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/`.
130+
6. Access the site at `http://localhost:8080`.
66131

67-
### Useful commands
132+
## Useful Commands
68133

69134
There are some useful commands you can use to manage the docker containers:
70135

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

73138
{% hint style="warning" %}
74139
Be careful with this command, as it deletes your database and all data in it.
@@ -77,7 +142,7 @@ Be careful with this command, as it deletes your database and all data in it.
77142
* `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.
78143
* `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.
79144

80-
## Details
145+
## Bind Mounts (SQL Server setup)
81146

82147
The docker compose file uses bind mounts for the following folders:
83148

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

92157
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.
93158

94-
## Template options
159+
## Template Options (SQL Server only)
95160

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

98163
* `-P` or `--project-name`: The name of the project. This is required and used to set the correct paths in the docker-compose file.
99164
* `-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)