Skip to content

Instantly share code, notes, and snippets.

@agrcrobles
Last active August 18, 2018 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agrcrobles/ab2a048d49311d32b621a7e95e3a582c to your computer and use it in GitHub Desktop.
Save agrcrobles/ab2a048d49311d32b621a7e95e3a582c to your computer and use it in GitHub Desktop.
aspnetcore.dockerfile
FROM microsoft/dotnet:sdk
LABEL author="Dan Wahlin"
ENV DOTNET_USE_POLLING_FILE_WATCHER=1
ENV ASPNETCORE_URLS=http://*:5000
EXPOSE 5000
WORKDIR /var/www/aspnetcoreapp
CMD ["/bin/bash", "-c", "dotnet restore && dotnet watch run"]
# Build the image:
# docker build -f aspnetcore.development.dockerfile -t [yourDockerHubID]/dotnet:1.0.0
# Option 1
# Start PostgreSQL and ASP.NET Core (link ASP.NET core to ProgreSQL container with legacy linking)
# docker run -d --name my-postgres -e POSTGRES_PASSWORD=password postgres
# docker run -d -p 5000:5000 --link my-postgres:postgres [yourDockerHubID]/dotnet:1.0.0
# 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 -e POSTGRES_PASSWORD=password postgres
# docker run -d --net=isolated_network --name aspnetcoreapp -p 5000:5000 [yourDockerHubID]/dotnet:1.0.0
FROM microsoft/dotnet:sdk
LABEL author="Dan Wahlin"
ENV ASPNETCORE_URLS=http://*:5000
WORKDIR /var/www/aspnetcoreapp
COPY . .
EXPOSE 5000
ENTRYPOINT ["/bin/bash", "-c", "dotnet restore && dotnet run"]
# Note that this is only for demo and is intended to keep things simple.
# A multi-stage dockerfile would normally be used here to build the .dll and use
# the microsoft/dotnet:aspnetcore-runtime image for the final image
# Build the image:
# docker build -f aspnetcore.production.dockerfile -t [yourDockerHubID]/dotnet:1.0.0
# docker push
# Option 1
# Start PostgreSQL and ASP.NET Core (link ASP.NET core to ProgreSQL container with legacy linking)
# docker run -d --name my-postgres -e POSTGRES_PASSWORD=password postgres
# docker run -d -p 5000:5000 --link my-postgres:postgres [yourDockerHubID]/dotnet:1.0.0
# 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 -e POSTGRES_PASSWORD=password postgres
# docker run -d --net=isolated_network --name aspnetcoreapp -p 5000:5000 [yourDockerHubID]/dotnet:1.0.0
#!/bin/bash
#.docker folder
set -e
host="$1"
shift
cmd="$@"
until psql -h "$host" -U "postgres" -c '\l'; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - executing command"
exec $cmd
#Can call from docker-compose.yml by adding the following to dependent service entrypoint: ./.docker/wait-for-postgres.sh postgres:5432
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment