danwahlin / aspnetcorepostgresqldockerapp Goto Github PK
View Code? Open in Web Editor NEWASP.NET Core with PostgreSQL Docker App Demo
ASP.NET Core with PostgreSQL Docker App Demo
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
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:
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?
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]
docker-compose build passes
docker-compose up fails as below
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
How can i apply migrations inside a Docker Container? So when the container start creates all tables on database.
I'm going through Chapter 7 and trying to run this command manually in the terminal:
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:
Any advice is appreciated!
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
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.
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.
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
WORKDIR /app
RUN dotnet restore
RUN dotnet build
EXPOSE 5000/tcp
RUN ["dotnet", "ef", "database", "update"]
ENTRYPOINT ["dotnet", "run", "--server.urls", "http://0.0.0.0:5000"]
basically I have Migrations that works great in dev however getting it to deploy migrations when its deployed to docker with postgres it fails.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.