Skip to content

Commit af302ed

Browse files
author
Francisco Beltrao
committed
Added Docker support for Sample projects
1 parent efcfc0b commit af302ed

25 files changed

Lines changed: 334 additions & 8 deletions

DockerSupport.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Docker Support JavaScriptServices
2+
3+
Using Visual Studio 2017 you can right click each project and Add Docker Support. Visual Studio will create a Dockerfile for the project and register it in the docker-compose section of your solution.
4+
The Dockerfile created by Visual Studio looks like this:
5+
```
6+
FROM microsoft/aspnetcore:1.1
7+
ARG source
8+
WORKDIR /app
9+
EXPOSE 80
10+
COPY ${source:-obj/Docker/publish} .
11+
ENTRYPOINT ["dotnet", "MusicStore.dll"]
12+
```
13+
14+
The problem is that JavaScriptServices needs NodeJS to run, which is not available on the microsoft/aspnetcore:1.1 image. We need to install it before starting the application.
15+
Change the Dockerfile like this:
16+
```
17+
FROM microsoft/aspnetcore:1.1
18+
RUN apt-get update
19+
RUN apt-get install curl
20+
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash
21+
RUN apt-get install -y build-essential nodejs
22+
ARG source
23+
WORKDIR /app
24+
EXPOSE 80
25+
COPY ${source:-obj/Docker/publish} .
26+
ENTRYPOINT ["dotnet", "MusicStore.dll"]
27+
```
28+
29+
Docker support was added to all sample projects. The React MusicStore is not work properly due to a webpack error.
30+
31+
## Running with Docker
32+
To run the application inside Docker, make sure that docker-compose is the Start-up project on your solution. Then, simply press F5 which will run all configured samples in a docker container.
33+
To browse go to the command line and type:
34+
```
35+
docker ps
36+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
37+
8da5f8ec45fe reactmusicstore:dev "tail -f /dev/null" 12 minutes ago Up 12 minutes 0.0.0.0:32779->80/tcp dockercompose3094088439_reactmusicstore_1
38+
16593eafd06a reactgrid:dev "tail -f /dev/null" 12 minutes ago Up 12 minutes 0.0.0.0:32780->80/tcp dockercompose3094088439_reactgrid_1
39+
7fda780decb0 ngmusicstore:dev "tail -f /dev/null" 12 minutes ago Up 12 minutes 0.0.0.0:32778->80/tcp dockercompose3094088439_ngmusicstore_1
40+
7c0d49413df6 nodeservicesexamples:dev "tail -f /dev/null" 12 minutes ago Up 12 minutes 0.0.0.0:32777->80/tcp dockercompose3094088439_nodeservicesexamples_1
41+
0f15ba2c085c reactgrid:dev "tail -f /dev/null" About an hour ago Up About an hour 0.0.0.0:32772->80/tcp dockercompose4052802262_reactgrid_1
42+
```
43+
44+
If you open your browser on localhost:32778 you will see the Angular Music Store Sample. I've added in page footer information about the hosting environment.
45+
Under docker (at least for Windows) the footer should look like:
46+
```
47+
Running on 7fda780decb0 (Linux 4.9.12-moby #1 SMP Tue Feb 28 12:11:36 UTC 2017)
48+
```

JavaScriptServices.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26228.4
4+
VisualStudioVersion = 15.0.26228.9
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{27304DDE-AFB2-4F8B-B765-E3E2F11E886C}"
77
EndProject
@@ -64,6 +64,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{E415FE14
6464
EndProject
6565
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VueSpa", "templates\VueSpa\VueSpa.csproj", "{49D7665A-20EC-43FC-B8E8-EA0204F2D8C3}"
6666
EndProject
67+
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{C3E26FF2-401F-4E8A-BF19-49E868529039}"
68+
EndProject
6769
Global
6870
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6971
Debug|Any CPU = Debug|Any CPU
@@ -142,6 +144,10 @@ Global
142144
{49D7665A-20EC-43FC-B8E8-EA0204F2D8C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
143145
{49D7665A-20EC-43FC-B8E8-EA0204F2D8C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
144146
{49D7665A-20EC-43FC-B8E8-EA0204F2D8C3}.Release|Any CPU.Build.0 = Release|Any CPU
147+
{C3E26FF2-401F-4E8A-BF19-49E868529039}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
148+
{C3E26FF2-401F-4E8A-BF19-49E868529039}.Debug|Any CPU.Build.0 = Debug|Any CPU
149+
{C3E26FF2-401F-4E8A-BF19-49E868529039}.Release|Any CPU.ActiveCfg = Release|Any CPU
150+
{C3E26FF2-401F-4E8A-BF19-49E868529039}.Release|Any CPU.Build.0 = Release|Any CPU
145151
EndGlobalSection
146152
GlobalSection(SolutionProperties) = preSolution
147153
HideSolutionNode = FALSE

docker-compose.ci.build.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: '2'
2+
3+
services:
4+
ci-build:
5+
image: microsoft/aspnetcore-build:1.0-1.1
6+
volumes:
7+
- .:/src
8+
working_dir: /src
9+
command: /bin/bash -c "dotnet restore ./JavaScriptServices.sln && dotnet publish ./JavaScriptServices.sln -c Release -o ./obj/Docker/publish"

docker-compose.dcproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
3+
<PropertyGroup Label="Globals">
4+
<ProjectGuid>c3e26ff2-401f-4e8a-bf19-49e868529039</ProjectGuid>
5+
<DockerLaunchBrowser>True</DockerLaunchBrowser>
6+
<DockerServiceUrl>http://localhost:{ServicePort}</DockerServiceUrl>
7+
<DockerServiceName>musicstore</DockerServiceName>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<None Include="docker-compose.ci.build.yml" />
11+
<None Include="docker-compose.override.yml">
12+
<DependentUpon>docker-compose.yml</DependentUpon>
13+
</None>
14+
<None Include="docker-compose.vs.debug.yml">
15+
<DependentUpon>docker-compose.yml</DependentUpon>
16+
</None>
17+
<None Include="docker-compose.vs.release.yml">
18+
<DependentUpon>docker-compose.yml</DependentUpon>
19+
</None>
20+
<None Include="docker-compose.yml" />
21+
</ItemGroup>
22+
</Project>

docker-compose.override.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: '2'
2+
3+
services:
4+
ngmusicstore:
5+
environment:
6+
- ASPNETCORE_ENVIRONMENT=Development
7+
ports:
8+
- "80"
9+
10+
nodeservicesexamples:
11+
environment:
12+
- ASPNETCORE_ENVIRONMENT=Development
13+
ports:
14+
- "80"
15+
16+
reactmusicstore:
17+
environment:
18+
- ASPNETCORE_ENVIRONMENT=Development
19+
ports:
20+
- "80"
21+
22+
reactgrid:
23+
environment:
24+
- ASPNETCORE_ENVIRONMENT=Development
25+
ports:
26+
- "80"

docker-compose.vs.debug.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
version: '2'
2+
3+
services:
4+
ngmusicstore:
5+
image: ngmusicstore:dev
6+
build:
7+
args:
8+
source: ${DOCKER_BUILD_SOURCE}
9+
environment:
10+
- DOTNET_USE_POLLING_FILE_WATCHER=1
11+
volumes:
12+
- ./samples/angular/MusicStore:/app
13+
- ~/.nuget/packages:/root/.nuget/packages:ro
14+
- ~/clrdbg:/clrdbg:ro
15+
entrypoint: tail -f /dev/null
16+
labels:
17+
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
18+
19+
nodeservicesexamples:
20+
image: nodeservicesexamples:dev
21+
build:
22+
args:
23+
source: ${DOCKER_BUILD_SOURCE}
24+
environment:
25+
- DOTNET_USE_POLLING_FILE_WATCHER=1
26+
volumes:
27+
- ./samples/misc/NodeServicesExamples:/app
28+
- ~/.nuget/packages:/root/.nuget/packages:ro
29+
- ~/clrdbg:/clrdbg:ro
30+
entrypoint: tail -f /dev/null
31+
labels:
32+
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
33+
34+
reactmusicstore:
35+
image: reactmusicstore:dev
36+
build:
37+
args:
38+
source: ${DOCKER_BUILD_SOURCE}
39+
environment:
40+
- DOTNET_USE_POLLING_FILE_WATCHER=1
41+
volumes:
42+
- ./samples/react/MusicStore:/app
43+
- ~/.nuget/packages:/root/.nuget/packages:ro
44+
- ~/clrdbg:/clrdbg:ro
45+
entrypoint: tail -f /dev/null
46+
labels:
47+
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
48+
49+
reactgrid:
50+
image: reactgrid:dev
51+
build:
52+
args:
53+
source: ${DOCKER_BUILD_SOURCE}
54+
environment:
55+
- DOTNET_USE_POLLING_FILE_WATCHER=1
56+
volumes:
57+
- ./samples/react/ReactGrid:/app
58+
- ~/.nuget/packages:/root/.nuget/packages:ro
59+
- ~/clrdbg:/clrdbg:ro
60+
entrypoint: tail -f /dev/null
61+
labels:
62+
- "com.microsoft.visualstudio.targetoperatingsystem=linux"

docker-compose.vs.release.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
version: '2'
2+
3+
services:
4+
ngmusicstore:
5+
build:
6+
args:
7+
source: ${DOCKER_BUILD_SOURCE}
8+
volumes:
9+
- ~/clrdbg:/clrdbg:ro
10+
entrypoint: tail -f /dev/null
11+
labels:
12+
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
13+
14+
nodeservicesexamples:
15+
build:
16+
args:
17+
source: ${DOCKER_BUILD_SOURCE}
18+
volumes:
19+
- ~/clrdbg:/clrdbg:ro
20+
entrypoint: tail -f /dev/null
21+
labels:
22+
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
23+
24+
reactmusicstore:
25+
build:
26+
args:
27+
source: ${DOCKER_BUILD_SOURCE}
28+
volumes:
29+
- ~/clrdbg:/clrdbg:ro
30+
entrypoint: tail -f /dev/null
31+
labels:
32+
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
33+
34+
reactgrid:
35+
build:
36+
args:
37+
source: ${DOCKER_BUILD_SOURCE}
38+
volumes:
39+
- ~/clrdbg:/clrdbg:ro
40+
entrypoint: tail -f /dev/null
41+
labels:
42+
- "com.microsoft.visualstudio.targetoperatingsystem=linux"

docker-compose.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: '2'
2+
3+
services:
4+
ngmusicstore:
5+
image: ngmusicstore
6+
build:
7+
context: ./samples/angular/MusicStore
8+
dockerfile: Dockerfile
9+
10+
nodeservicesexamples:
11+
image: nodeservicesexamples
12+
build:
13+
context: ./samples/misc/NodeServicesExamples
14+
dockerfile: Dockerfile
15+
16+
reactmusicstore:
17+
image: reactmusicstore
18+
build:
19+
context: ./samples/react/MusicStore
20+
dockerfile: Dockerfile
21+
22+
reactgrid:
23+
image: reactgrid
24+
build:
25+
context: ./samples/react/ReactGrid
26+
dockerfile: Dockerfile
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
!obj/Docker/publish/*
3+
!obj/Docker/empty/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM microsoft/aspnetcore:1.1
2+
RUN apt-get update
3+
RUN apt-get install curl
4+
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash
5+
RUN apt-get install -y build-essential nodejs
6+
ARG source
7+
WORKDIR /app
8+
EXPOSE 80
9+
COPY ${source:-obj/Docker/publish} .
10+
ENTRYPOINT ["dotnet", "MusicStore.dll"]

0 commit comments

Comments
 (0)