When setting up ngrok on my Vapor server application, using a docker container, I cannot manage to create a secure web connection using a custom domain that I own.
I would like to use my docker-compose.yml
file to read the ngrok.yml
one with the setup, but I have had a better result using the command line.
Let say the owned domain is: api.personal_domain.com
.
The CNAME DNS record from ngrok.com is added to my domain provider.
I run this command to start the "secure web connection" on localhost.
$ docker run -it -e NGROK_AUTHTOKEN=<NGROK_PERSONAL_TOKEN> ngrok/ngrok http https://127.0.0.1:8080 --domain=api.personal_domain.com
But still a failure occurs with a 404 Not Found
. I can see that the server is not receiving the request.
This is the configuration of the postgres data base made on the Vapor application:
app.databases.use(.postgres(
hostname: "api.personal_domain.com",
port: 5433,
username: "user_stackoverflow",
password: "password_stackoverflow",
database: "personal_domain_db_develop"
), as: .psql)
This is the setup in the docker-compose.yml
file:
ngrok:
image: ngrok:latest
restart: unless-stopped
command:
- "start"
- "--all"
- "--config"
- "/etc/ngrok.yml"
volumes:
- ./ngrok.yml:/etc/ngrok.yml
ports:
- 4040:
And the ngrok.yml
file is set this way:
version: "2"
authtoken: <NGROK_PERSONAL_TOKEN>
tunnels:
server:
addr: 5433
proto: http
host_header: localhost
domain: api.personal_domain.com
From there, I run $ docker compose up
in the Terminal but an error occurs.
[+] Running 1/1
✘ ngrok Error 2.1s
Error response from daemon: pull access denied for ngrok, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
I would like to have a secure HTTPS connection when developing my server on localhost using docker.
How can I setup the ngrok tunnel properly for my Vapor application to run locally on a secure web connection?
2
Answers
PM from ngrok here. As mentioned by @john-hanley, you should be using
image: ngrok/ngrok:latest
in your docker compose file. Here is a link to the ngrok documentation page for using ngrok with Docker.Also, I noticed that in your first docker command, you are using port 4040, which happens to be a port that ngrok uses by default for a local inspection interface and agent API. Based on your configuration file, the docker command you need is:
docker run --net=host -it -e NGROK_AUTHTOKEN=xyz ngrok/ngrok:latest http 5433 --domain api.personal_domain.com
If you are on a Mac or Windows machine, the command would be:
docker run -it -e NGROK_AUTHTOKEN=xyz ngrok/ngrok:latest http host.docker.internal:5433 --domain api.personal_domain.com
From "Using ngrok with Docker Compose", try and use a
docker-compose.yml
file like:With a
ngrok.yml
set to use an HTTPS connection:Update your Vapor app to listen on all interfaces (
app.http.server.configuration.hostname = "0.0.0.0"
): that should be inconfigure.swift
file in theSources/App
directory.And update your database connection configuration in the Vapor app to use the correct hostname ("db") and port (5432):
https://api.personal_domain.com should then be available after
docker-compose up
.