Coder Social home page Coder Social logo

aspnetcorepostgresqldockerapp's Introduction

ASP.NET Core with PostgreSQL and Docker Demo

Application demo designed to show how ASP.NET Core and PostgreSQL can be run in Docker containers. The app uses Entity Framework to create a simple database that stores Docker commands and examples. It also shows how Angular can be integrated with Web API to display customer information.

Running the App with Docker Compose

  1. Install Docker Desktop for Mac or Docker Desktop for Windows.

  2. Navigate to the AspNetCorePostgreSQLDockerApp subfolder in a console window.

  3. Open the Client folder in a terminal window and run the following commands at the root of the folder (requires Node.js):

    • npm install
    • npm install -g @angular/cli
    • ng build
  4. Move back up a level to the AspNetCorePostgreSQLDockerApp in the terminal window:

    • Run docker-compose build

    • Run docker-compose up

  5. Navigate to http://localhost:5000 in your browser to view the site.

Using the Web App for Container Services on Azure

  1. Run docker-compose -f docker-compose.prod.yml build.
  2. Tag the aspnetcoreapp image as [yourDockerHubUserAccount]/aspnetcoreapp. Make sure you substitute your Docker Hub user account for [yourDockerHubUserAccount].
  3. Push the image to Docker Hub using docker push [yourDockerHubUserAccount]/aspnetcoreapp.
  4. Open docker-compose azure.yml file and change the image for the web service to [yourDockerHubUserAccount]/aspnetcoreapp.
  5. Create a new Web App for Containers service in Azure. You'll need to add it to a new or existing Resource Group.
  6. On the Docker tab, switch Options to Docker Compose, Image Source to Docker Hub and upload the docker-compose azure.yml file using the Configuration File section of the screen.
  7. Wait for the service to start (it may take a few minutes to pull the image and fire up the Web App Service) and then click the web link it provides in the Overview section to hit the app.

aspnetcorepostgresqldockerapp's People

Contributors

danwahlin avatar dependabot[bot] avatar spboyer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aspnetcorepostgresqldockerapp's Issues

.net core 2

Hey Dan,

Just tied this with .net core 2 and get the following

Data/ApplicationDbContext.cs(16,18): error CS0311: The type 'Dashboard.Models.ApplicationUser' cannot be used as type parameter 'TUser' in the generic type or method 'IdentityDbContext'. There is no implicit reference conversion from 'Dashboard.Models.ApplicationUser' to 'Microsoft.AspNetCore.Identity.IdentityUser'. [/Users/JonHallam2/project new /Dashboard/DashboardCoreVs2017-2/Dashboard.csproj]

Attach volume required?

I'm testing out manual linking using the following command but it fails with an error that it cannot find a .sln or .csproj to build:

# docker run -d -p 5000:5000 --link my-postgres:postgres [yourDockerHubID]/dotnet:1.0.0

I resolved it by attaching a volume to it, by adding -v $(pwd):/var/www/aspnetcoreapp whereby the current directory is where the .csproj file is. It didn't work if my present directory was where the .sln is.

The issue is: Is there a scenario where the given code snippet should work, without me having to add a volume?

Cannot connect to http://192.168.99.100:5000/ using Docker Toolbox

What do you think is wrong. I am using Docker Toolbox and accessing this at http://192.168.99.100:5000/

Starting postgres
Recreating aspnetcoreapp
Attaching to postgres, aspnetcoreapp
postgres    | LOG:  database system was shut down at 2016-10-01 19:33:12 UTC
postgres    | LOG:  MultiXact member wraparound protections are now enabled
postgres    | LOG:  database system is ready to accept connections
postgres    | LOG:  autovacuum launcher started
aspnetcoreapp | [DotNetWatcher] info: Running dotnet with the following arguments: run --server.urls http://0.0.0.0:5000
aspnetcoreapp | [DotNetWatcher] info: dotnet process id: 31
aspnetcoreapp | Project WebAPI.Data (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
aspnetcoreapp | Project WebAPI.Domain (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
aspnetcoreapp | Project WebAPI (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
aspnetcoreapp | dbug: Npgsql.NpgsqlConnection[3]
aspnetcoreapp |       Opening connection to database 'webapi' on server 'tcp://postgres:5432'.
aspnetcoreapp | info: Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommandBuilderFactory[1]
aspnetcoreapp |       Executed DbCommand (1,219ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
aspnetcoreapp |       SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace WHERE c.relname='__EFMigrationsHistory');
aspnetcoreapp | dbug: Npgsql.NpgsqlConnection[4]
aspnetcoreapp |       Closing connection to database 'webapi' on server 'tcp://postgres:5432'.
aspnetcoreapp | dbug: Npgsql.NpgsqlConnection[3]
aspnetcoreapp |       Opening connection to database 'webapi' on server 'tcp://postgres:5432'.
aspnetcoreapp | info: Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommandBuilderFactory[1]
aspnetcoreapp |       Executed DbCommand (105ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
aspnetcoreapp |       SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace WHERE c.relname='__EFMigrationsHistory');
aspnetcoreapp | dbug: Npgsql.NpgsqlConnection[4]
aspnetcoreapp |       Closing connection to database 'webapi' on server 'tcp://postgres:5432'.
aspnetcoreapp | dbug: Npgsql.NpgsqlConnection[3]
aspnetcoreapp |       Opening connection to database 'webapi' on server 'tcp://postgres:5432'.
aspnetcoreapp | info: Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommandBuilderFactory[1]
aspnetcoreapp |       Executed DbCommand (239ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
aspnetcoreapp |       SELECT "MigrationId", "ProductVersion"
aspnetcoreapp |       FROM "__EFMigrationsHistory"
aspnetcoreapp |       ORDER BY "MigrationId";
aspnetcoreapp | dbug: Npgsql.NpgsqlConnection[4]
aspnetcoreapp |       Closing connection to database 'webapi' on server 'tcp://postgres:5432'.
aspnetcoreapp | Hosting environment: Production
aspnetcoreapp | Content root path: /app/src/WebAPI
aspnetcoreapp | Now listening on: http://localhost:5000
aspnetcoreapp | Application started. Press Ctrl+C to shut down.

docker up failed for creating volume

Hi Dan,

I followed exactly what you wrote but i get the following error when i do docker-compose up:
ERROR: for aspnetcoreapp Cannot create container for service web: invalid volume specification: 'D:\test\AspNetCorePostgreSQLDockerApp-master\AspNetCorePostgreSQLDockerApp:/var/www/aspnetcoreapp:rw'

I work on windows 10.
Any idea ?
Thanks.

Manually building image results in docker build error

I'm going through Chapter 7 and trying to run this command manually in the terminal:

# docker build -f aspnetcore.development.dockerfile -t [yourDockerHubID]/dotnet:1.0.0

I get the following error:

ZemienMacbook:AspNetCorePostgreSQLDockerApp zemien$ docker build -f aspnetcore.development.dockerfile -t zemien/dotnet:1.0.0 
"docker build" requires exactly 1 argument.
See 'docker build --help'.

Usage:  docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile

I have replaced [yourDockerHubID] with a username, but I also get the same error if I remove the whole tag option and leave -f in there.

I should note that the containers work when I use docker-compose build and docker-compose up, as outlined in Readme.md. But I wanted to build up my layers of knowledge by following the example.

System info:

  • Mac OS Mojave
  • Docker CE 2.0.0.3
  • Docker Engine 18.09.2

Any advice is appreciated!

aspnetcore.development.dockerfile fail

FYI Environment Windows 10 machine
aspnetcore proj fails on build cant find csproj

Fix

(1)
aspnetcore.development.dockerfile
/*
FROM microsoft/dotnet:2.1-sdk

LABEL author="Dan Wahlin"

ENV DOTNET_USE_POLLING_FILE_WATCHER=1
ENV ASPNETCORE_URLS=http://*:5000

EXPOSE 5000

WORKDIR /var/www/aspnetcoreapp

COPY AspNetCorePostgreSQLDockerApp.csproj .

CMD ["/bin/bash", "-c", "dotnet restore AspNetCorePostgreSQLDockerApp.csproj && dotnet run"]
*/

(2)
docker build -f aspnetcore.development.dockerfile -t [insert docker id]/dotnet:1.0.0 .

(3)
docker run -d -p 5000:5000 -v "%cd%":/var/www/aspnetcoreapp --link my-postgres:postgres [insert docker id]/dotnet:1.0.0

compose up fails

docker-compose build passes
docker-compose up fails as below

danwahlin

pradeep@seleniumframework>docker info
Containers: 2
 Running: 0
 Paused: 0
 Stopped: 2
Images: 23
Server Version: 1.11.0
Storage Driver: aufs
 Root Dir: /mnt/sda1/var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 109
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge null host
Kernel Version: 4.1.19-boot2docker
Operating System: Boot2Docker 1.11.0 (TCL 7.0); HEAD : 32ee7e9 - Wed Apr 13 20:06:49 UTC 2016
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.956 GiB
Name: default
ID: FPNF:IOLP:R67R:5JQ2:EMQX:ZUKM:DBNV:3NUZ:UUKN:G2QL:5325:4ZUO
Docker Root Dir: /mnt/sda1/var/lib/docker
Debug mode (client): false
Debug mode (server): true
 File Descriptors: 13
 Goroutines: 30
 System Time: 2016-04-30T01:15:24.064491054Z
 EventsListeners: 0
Registry: https://index.docker.io/v1/
Labels:
 provider=virtualbox

Can't run local, and docker compose doesn't work?

Hi,

I've got two (probably newbie) issues :

I cant seem to build the project and run it locally? I'm using..
.NET Command Line Tools (1.0.0-preview3-004056)
Product Information:
Version: 1.0.0-preview3-004056
Commit SHA-1 hash: ccc4968bc3

Runtime Environment:
OS Name: Windows
OS Version: 10.0.10586
OS Platform: Windows
RID: win10-x64

I've tried dotnet run , but it keeps telling me :

MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.

And the second thing, when I try docker-compose build i get the following:

IOError: [Errno 13] Permission denied: 'C:\source\AspNetCorePostgreSQLDockerApp.vs\AspNetCorePostgreSQLDockerApp\v15\Browse.VC.opendb'
docker-compose returned -1

If it's a totally dumb question, i'm sorry.

With kind regards,

Frank

Using Docker Compose

Hi, When I follow both your Pluralsight training and your code. I cant seam to get it to build the docker images.
Ive set the connection string to
var connectionString = "User ID=postgres;Password=password;Server=localhost;Port=5432;Database=postgres;Integrated Security=true;Pooling=true;";

then doing a docker build

docker build -f core.development.dockerfile -t Username/core:latest .

it errors with

An error occurred while calling method 'ConfigureServices' on startup class 'Core.Startup'. Consider using IDbContextFactory to o
verride the initialization of the DbContext at design-time.

Error: Connection refused
System.Net.Sockets.SocketException: Connection refused
at Npgsql.NpgsqlConnector.Connect(NpgsqlTimeout timeout)
at Npgsql.NpgsqlConnector.RawOpen(NpgsqlTimeout timeout)
at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout)
at Npgsql.ConnectorPool.Allocate(NpgsqlConnection conn, NpgsqlTimeout timeout)
at Npgsql.NpgsqlConnection.OpenInternal()
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open()
at Microsoft.EntityFrameworkCore.Storage.Internal.NpgsqlDatabaseCreator.Exists()
at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Tools.Cli.DatabaseUpdateCommand.<>c__DisplayClass0_0.b__0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
Connection refused

the solution runs fine its now getting it to build in to docker.

My docker file is below.

FROM microsoft/dotnet:latest

MAINTAINER Jon Hallam

ENV DOTNET_USE_POLLING_FILE_WATCHER=1

COPY . /app

COPY ./package.json /var/www/aspnetcoreapp/package.json

WORKDIR /app

RUN dotnet restore

RUN dotnet build

EXPOSE 5000/tcp

RUN ["dotnet", "ef", "database", "update"]

ENTRYPOINT ["dotnet", "watch", "run", "--server.urls", "http://0.0.0.0:5000"]

ENTRYPOINT ["dotnet", "run", "--server.urls", "http://0.0.0.0:5000"]

Build the image:

docker build -f core.development.dockerfile -t username/core:latest .

Option 1

Start PostgreSQL and ASP.NET Core (link ASP.NET core to ProgreSQL container with legacy linking)

docker run -d --name my-postgres -p 5432:5432 -e POSTGRES_PASSWORD=password postgres

docker run -d -p 5000:5000 --link my-postgres:postgres username/core:latest

Option 2: Create a custom bridge network and add containers into it

docker network create --driver bridge isolated_network

docker run -d --net=isolated_network --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=password postgres

docker run -d --net=isolated_network --name aspnetcoreapp -p 5000:5000 username/core:latest

basically I have Migrations that works great in dev however getting it to deploy migrations when its deployed to docker with postgres it fails.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.