Deploying Server-Side Swift Apps With Docker on Heroku

In this tutorial, you’ll learn how to deploy server-side applications developed in Vapor as well as Docker images of your application into Heroku. By Natan Rolnik.

4.5 (2) · 1 Review

Download materials
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Reading Server Logs

If you’ve encountered any errors or want to see your app’s logs to troubleshoot or get more information, the logs command is very helpful. It displays logs from both Heroku and the Vapor app.

heroku logs

This displays the recent log output from your app. If you want to see live logs, pass the --tail flag:

Logs are very useful to understand what’s happening with your app

App logs filling the screen
Note: Although this tutorial explains the different steps of the process of building and pushing the image, the Heroku CLI provides a single command that wraps the commands in this section. You can try it for yourself in the next deploy: heroku container:push web. Alternatively, you can also write a script that packages the instructions from this section to ease the deployment process.

Letting Heroku Build the Image for You

Note: Consider this part of the tutorial as optional or a bonus, as you might be perfectly fine with local builds and uploads, especially if they’re not too frequent.

The process of building locally and uploading images to the registry can be tiring when deployments are frequent. But there’s good news, this task can be automated!

Creating the heroku.yml File

Heroku allows developers to add a yml configuration file at the root of the app repository. Amongst other things, this file defines how Heroku, not your machine, should perform the build and automatically release Docker images of your app.

In your text editor of choice, create a file named heroku.yml at the root of the project, and paste the three lines below:

build:
  docker:
    web: Dockerfile

This is enough to tell Heroku to use Docker to build an image, using the Dockerfile at the root of the project to build your app image and release it to the web process.

You must track this file in the app’s Git repository. To do so, run:

git add heroku.yml
git commit -a -m "Add heroku.yml"

To confirm the repository contains the Heroku Git remote, run git remote -v. You’ll see a remote URL in the https://git.heroku.com/<your-app-name>.git pattern.

After certifying the Heroku Git remote is present, perform a git push to it:

git push heroku master

As Heroku receives your new commit, it starts building the new image, and the git push operation logs the progress:

Pushing your app’s repository for Heroku to build

Pushing your app's repository for Heroku to build

After a few minutes, you’ll see a confirmation that the app was deployed, this time with the image originating from Heroku’s builder machines rather than your own computer!

Sometimes, if the build process is long, the SSH connection might drop, and Git will display an error message unrelated to the build. If that happens, Heroku will continue building, and you can access the app dashboard in the browser. Click the Activity tab, and then look for the build in progress:

Heroku displaying the current build logs

 Heroku displaying the current build logs

After a few minutes, the build will complete, and your app will run the latest code you just deployed.

Where to Go From Here?

Congratulations! You’ve reached the end of this tutorial, and now you know how to create Heroku apps, configure add-ons, and build and deploy Docker containers.

Download the completed project from this tutorial using the Download Materials button at the top and bottom of this page.

If you’re looking to learn more, here are some ideas and challenges:

  • Add more add-ons, such as Heroku Redis for caching, or others available in the Heroku Marketplace.
  • If you own a domain, set up a custom domain for your app, which allows you to hide the *.herokuapp.com domain.
  • Automate and set up continuous delivery, either with the Heroku CI and Pipelines or with GitHub Actions.
  • Deploy different environments with pipelines. For example, enable a staging environment to test your web app and its API before deploying to production.

To learn more about Server-Side Swift, Vapor and other deployment techniques, check out:

If you have any questions or comments, please join the forum discussion below!