Deploy a Gin App

Gin is a high-performance web framework for Go (Golang) that provides a martini-like API while being significantly faster—up to 40 times—due to its use of httprouter. It's designed for developers seeking both speed and productivity.

This guide covers how to deploy a Gin app on Railway in four ways:

  1. One-click deploy from a template.
  2. From a GitHub repository.
  3. Using the CLI.
  4. Using a Dockerfile.

One-Click Deploy From a Template

Deploy on Railway

We highly recommend that you eject from the template after deployment to create a copy of the repo on your GitHub account.

Note: You can also choose from a variety of Gin app templates created by the community.

Deploy From a GitHub Repo

To deploy a Gin app on Railway directly from GitHub, follow the steps below:

  1. Fork the basic Gin GitHub repo.
    • If you already have a GitHub repo you want to deploy, you can skip this step.
  2. Create a New Project.
  3. Click Deploy from GitHub repo.
  4. Select the gin or your own GitHub repo.
    • Railway requires a valid GitHub account to be linked. If your Railway account isn't associated with one, you will be prompted to link it.
  5. Click Deploy Now.

Once the deployment is successful, a Railway service will be created for you. By default, this service will not be publicly accessible.

To set up a publicly accessible URL for the service, navigate to the Networking section in the Settings tab of your new service and click on Generate Domain.

screenshot of the deployed gin service showing a hello world API response on a browser

Deploy From the CLI

  1. Install and authenticate with the CLI.
  2. Clone the forked gin GitHub repo and cd into the directory.
    • You can skip this step if you already have an app directory or repo on your machine that you want to deploy.
  3. Run railway init within the app directory to create a new project.
  4. Run railway up to deploy.
    • The CLI will now scan, compress and upload our gin app files to Railway's backend for deployment.

Use a Dockerfile

  1. Clone the forked gin repo and cd into the directory.
    • You can skip this step if you already have an app directory or repo on your machine that you want to deploy.
  2. Create a Dockerfile in the gin or app's root directory.
  3. Add the content below to the Dockerfile:
    # Use the Go 1.23 alpine official image
    # https://hub.docker.com/_/golang
    FROM golang:1.23-alpine
    
    # Create and change to the app directory.
    WORKDIR /app
    
    # Copy go mod and sum files
    COPY go.mod go.sum ./
    
    # Copy local code to the container image.
    COPY . ./
    
    # Install project dependencies
    RUN go mod download
    
    # Build the app
    RUN go build -o app
    
    # Run the service on container startup.
    ENTRYPOINT ["./app"]
  4. Either deploy via the CLI or from GitHub.

Railway automatically detects the Dockerfile, and uses it to build and deploy the app.

Note: Railway supports also deployment from public and private Docker images.

Next Steps

Explore these resources to learn how you can maximize your experience with Railway:


Edit this file on GitHub