Skip to content

Commit

Permalink
Add docker support - docker for Web app and docker-compose for nginx …
Browse files Browse the repository at this point in the history
…and aspnet support.
  • Loading branch information
RickStrahl committed Apr 25, 2017
1 parent 34175a0 commit 0f40953
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 0 deletions.
46 changes: 46 additions & 0 deletions AlbumViewer_Docker.websurge
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
GET http://localhost:8081/index.html HTTP/1.1
Accept-Encoding: gzip,deflate

------------------------------------------------------------------

GET http://localhost:8081/api/artist/1 HTTP/1.1
Accept-Encoding: gzip,deflate

------------------------------------------------------------------

GET http://localhost:8081/api/helloworld HTTP/1.1
Accept-Encoding: gzip,deflate

------------------------------------------------------------------


----- Start WebSurge Options -----

{
"NoProgressEvents": true,
"DelayTimeMs": -1,
"NoContentDecompression": false,
"CaptureMinimalResponseData": false,
"MaxResponseSize": 0,
"ReplaceCookieValue": null,
"ReplaceAuthorization": null,
"ReplaceQueryStringValuePairs": null,
"ReplaceDomain": "",
"Username": null,
"Password": null,
"RandomizeRequests": false,
"RequestTimeoutMs": 15000,
"WarmupSeconds": 2,
"ReloadTemplates": false,
"FormattedPreviewTheme": "visualstudio",
"LastThreads": 8,
"IgnoreCertificateErrors": false,
"LastSecondsToRun": 30
}

// This file was generated by West Wind WebSurge
// Get your free copy at http://websurge.west-wind.com
// to easily test or load test the requests in this file.

----- End WebSurge Options -----

38 changes: 38 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Run docker-compose build
# Run docker-compose up
# Live long and prosper

version: '2'

services:

nginx:
container_name: nginxalbumviewer
image: nginxalbumviewer
build:
context: ./nginx
dockerfile: Dockerfile
# volumes:.
# - ./dist:/usr/share/nginx/html
ports:
- "8081:80"
# - "443:443"
networks:
- app-network

aspnet:
container_name: 'westwindalbumviewer'
image: 'westwind/albumviewer:albumviewer'
build:
context: ./src/AlbumViewerNetCore
dockerfile: ./Dockerfile
# volumes:
# - ./src/AlbumViewerNetCore:/var/www/albumviewer
ports:
- "5000:5000"
networks:
- app-network

networks:
app-network:
driver: bridge
12 changes: 12 additions & 0 deletions dockercompose.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# dotnet publish -c Release
# robocopy ./src/albumviewernetcore/wwwroot ./nginx/wwwroot /MIR

docker rm westwind/albumviewer -f
docker rm nginxalbumviewer -f

docker-compose build

# docker-compose up
# docker-compose down

# docker network inspect albumviewervnext_app-network
20 changes: 20 additions & 0 deletions dockernginx.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Shut down running container
docker rm nginxalbumviewer -f

# Have to copy files from wwwroot in order to be part of context
robocopy ./src/albumviewernetcore/wwwroot ./nginx/wwwroot /MIR

# Build the image
docker build -t nginxalbumviewer:nginxalbumviewer ./nginx

# Run it
docker run -p 5003:80 --name nginxalbumviewer nginxalbumviewer:nginxalbumviewer


#docker stop nginxalbumviewer
#docker rm nginxalbumviewer

# docker exec -it nginxalbumviewer /bin/bash

# # if above doesn't work
# docker exec -it nginxalbumviewer /bin/sh
12 changes: 12 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM nginx:alpine

MAINTAINER Rick Strahl

# Copy custom nginx config
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY ./wwwroot /usr/share/nginx/html

EXPOSE 80 443

ENTRYPOINT ["nginx"]
CMD ["-g", "daemon off;"]
59 changes: 59 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
worker_processes 4;

events { worker_connections 1024; }

http {
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 30m;

#See http://blog.argteam.com/coding/hardening-node-js-for-production-part-2-using-nginx-to-avoid-node-js-load
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
proxy_temp_path /var/tmp;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;

gzip on;
gzip_comp_level 6;
gzip_vary on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;


server {
listen 80;

# Server name. You need a DNS record (or add this hostname to your hosts file)
#server_name core-app.local;

server_name localhost;

location / {
root /usr/share/nginx/html;
index index.html;
expires -1;
add_header web-server "nginx";
add_header Pragma "no-cache";
add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
try_files $uri$args $uri$args/ $uri $uri/ /index.html =404;
}

location /api {
proxy_pass http://dotnet;
add_header web-server "kestrel";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

upstream dotnet {
zone dotnet 64k;
server westwindalbumviewer:5000;
}
}
24 changes: 24 additions & 0 deletions src/AlbumViewerNetCore/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM microsoft/dotnet:1.1.1-sdk

MAINTAINER Rick Strahl

ENV ASPNETCORE_URLS=http://*:5000
ENV ASPNETCORE_ENVIRONMENT=Development

#
# Allow 1433 for SQL Server Access
EXPOSE 1433

# copy publish folder contents to web root
COPY ./bin/Release/netcoreapp1.1/publish /var/www/albumviewer

# Explicitly build app. Problems with this approach as multiple projects
#COPY . /var/www/albumviewer
#COPY ../AlbumViewerBusiness /var/www/AlbumViewerBusiness

WORKDIR /var/www/albumviewer

#CMD ["/bin/sh", "-c", "dotnet restore && dotnet publish -c Release && cd ./bin/Release/netcoreapp1.1/publish && dotnet AlbumViewerNetCore.dll"]

# Run out of Publish Folder
CMD ["/bin/sh", "-c", "dotnet 'AlbumViewerNetCore.dll'"]
21 changes: 21 additions & 0 deletions src/AlbumViewerNetCore/dockerbuild.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# publish the application first
dotnet publish -c Release

# clean up old image and any containers (running or not)
docker stop albumviewer
docker rm albumviewer -f
docker rmi westwind/albumviewer:albumviewer

# create new image
docker build -t westwind/albumviewer:albumviewer .

# immediately start running the container in the background (-d)
docker run -p 5004:5000 --name albumviewer westwind/albumviewer:albumviewer

#docker stop albumviewer
#docker rm albumviewer

# docker exec -it albumviewer /bin/bash

# # if above doesn't work
# docker exec -it albumviewer /bin/sh
17 changes: 17 additions & 0 deletions src/AlbumViewerNetCore/dockerbuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

dotnet publish -c Release

docker stop albumviewer
docker rm albumviewer -f

docker build -t westwind/albumviewer:albumviewer .

docker run -d -p 5004:5000 --name albumviewer westwind/albumviewer:albumviewer

#docker stop albumviewer
#docker rm albumviewer

# docker exec -it albumviewer /bin/bash

# # if above doesn't work
# docker exec -it albumviewer /bin/sh

0 comments on commit 0f40953

Please sign in to comment.