Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile example dockerfile work with $port #105

Open
nguyenloki258 opened this issue Feb 11, 2022 · 2 comments
Open

Dockerfile example dockerfile work with $port #105

nguyenloki258 opened this issue Feb 11, 2022 · 2 comments
Labels
content Anything to do with content

Comments

@nguyenloki258
Copy link

Hi, i'm trying deploy using Dockerfile. I dont know how to mapping port . Please help

@ndneighbor
Copy link

I think this is a valid concern and we have been getting these questions a lot. We can address this in an upcoming PR.

@TadijaB
Copy link

TadijaB commented Sep 25, 2022

If you are using Railway-Provided Domain (haven't yet tested it on custom domains) then the mapping is 443:$PORT

For example, if you Railway-Provided Domain is "foo.up.railway.app" and you successfully deployed a github repository with a Dockerfile then all requests to "https://foo.up.railway.app:443" will be transferred to container port defined by $PORT.

You can define $PORT in Varables and use it in Dockerfile to configure your dotnet core app like this:

Lets say:
PORT environment variable is 7001
Railway-Provided Domain is "foo.up.railway.app"

and Dockerfile looks like this:

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app

COPY . ./

RUN dotnet restore
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build-env /app/out .

ARG PORT
ENV PORT $PORT
ENV ASPNETCORE_URLS=http://+:$PORT

EXPOSE $PORT/tcp

RUN echo "ASPNETCORE_URLS: [$ASPNETCORE_URLS]"
RUN echo "PORT: [$PORT]"

ENTRYPOINT ["dotnet", "my-project.dll"]

When the project with this Dockerfile is deployed you should see Deploy Logs like this:

info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://[::]:7001
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /app/

So now all requests to "https://foo.up.railway.app:443" will hit your app inside the container on port 7001

@half0wl half0wl added the content Anything to do with content label Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content Anything to do with content
Projects
None yet
Development

No branches or pull requests

4 participants