How to Deploy Aspose.Words Cloud Docker Container on Heroku?

We saw that 22.1 included a fix WORDSCLOUD-1864 for using the Docker container on Heroku, and are trying this out. However, I’m not sure that the fix works.

Heroku requires that the docker container listen on a port specified by the environment variable $PORT; the default port that the Aspose container uses is not available. So the Aspose Docker container starts, tries to open a port, and crashes with a “System.Net.Sockets.SocketException (13): Permission denied” – because it’s using port 80 or 8082 or something.

If using the docker container on Heroku is indeed fixed, how can I configure the Aspose.Words docker container to listen on a specific port $PORT?

I’ve tried pretty much everything I can on my own here. I’ve found instructions on setting the port for ASP apps, e.g. Publishing ASP.NET Core application on Docker | by Thiago S. Adriano | dockerbr | Medium and .Net Core on Heroku with Docker - Stack Overflow

Those all suggest to set the port for the env attribute ASPNETCORE_URLS, which I’ve done:

ENV ASPNETCORE_URLS http://+:$PORT
CMD ASPNETCORE_URLS=http://+:$PORT dotnet Aspose.Words.Cloud.WebApp.dll

That’s still throwing the same error on Heroku, though. Seems that the Aspose container isn’t respecting that environment variable.

Error is specifically on Aspose.Words.Cloud.WebApp.Program.Main(String[] args) in C:\Build\src\Aspose.Words.Cloud.WebApp\Program.cs:line 25

@bmulhollandrecital

The referenced bug was about yaml file related issue at following documentation article.

I’m afraid I don’t have knowledge of the Heroku platform. You may please google or ask Heroku developers how to deploy Docker Container in Heroku. For example, you can try to use this stackoverflow answer:

stackoverflow.com

Benjamin Higgins

How can I run a Docker Hub container on Heroku via app.json?

docker, heroku

asked by Benjamin Higgins on 11:12AM - 02 Oct 19 UTC

This isn’t about the Heroku platform anymore. Heroku is working fine. There seems to be a bug that there is no way to make the Aspose Docker container listen on a specific port number – which is generally possible for ASP apps.

So, pretend I never said Heroku. The issue is this: I need the Aspose Docker container to listen on a specific port that is specified at runtime. I have configured ASP to use that port, and the Aspose Container is ignoring the configured port and instead listening at port 80. It should respect the ASP configuration option.

Also: I have Google’d this quite thoroughly, as you can see from my referenced links.

@bmulhollandrecital

Thanks for your detailed feedback. I am looking into the your issue and will update you soon.

@bmulhollandrecital

While investigating the issue, I found that when I run the Aspose.Words Cloud docker container with a custom port, it listens to the requests on the specified port without any issue. I will appreciate it if you please share some details to replicate the issue at my end. It will help us to address your issue.

docker run -p 8101:80 -e "User=tilalahmad" -e "Password=1234567890" -v "./fonts:/fonts" -v "./data:/data" --name aw_213 aspose/words-cloud

Generating Access Token(JWT)

curl -X POST "http://localhost:8101/connect/token" -d "grant_type=client_credentials&client_id=tilalahmad&client_secret=1234567890" -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json"

Hi Tilal, thanks for investigating.

The option you are using is simply providing a middleware firewall rule which uses docker’s published port feature – see here for more information: Networking overview | Docker Docs

What that means is that the docker container is still opening up port 80 on its host; the docker host is still allowing port 80, and simply redirecting that port to 8101. From the docker container’s perspective, it is still using port 80.

In this situation, the docker container is not permitted to use port 80, and there’s no firewall that can be used to redirect the port. In fact, even if we add a reverse proxy to the docker image (I tried this) that does effectively the same thing you have with -p, that operation still fails because Aspose’s host attempts to open port 80 and does not have permission to do so.

What is needed is to tell the web server that Aspose runs to use a different port. For example, Heroku recommends changing the CMD for a server to be CMD gunicorn --bind 0.0.0.0:$PORT wsgi. Translating it a bit, that command is saying "start a webserver (gunicorn) from any network the computer is attached to (0.0.0.0) and use port $PORT (instead of the default port 80).

You can see that the Aspose docker image configures the port to port 80 in line 4: Docker. Specifically, it configures an environment variable that tells ASP.NET Core to use port 80, as in “http://+:80”. But when I set that environment variable to a custom port, as you can see in my second post, the Aspose server ignores the configured port and still opens up port 80. And, again, that port 80 is still opened with the command you included – but docker is then opening up fort 8101 also, and redirecting the internal host port 80 to port 8101 on your computer.

FYI, since it’s behind a login, here’s what Heroku says about the PORT requirements:

When deploying a container app on Heroku, we require that Dockerfiles are configured to intake the randomly assigned port on a dyno - exposed as the $PORT environmental variable.

Even though Docker allows for the usage of EXPOSE to specify which port for an image to use, Heroku ignores those commands and goes by the port assigned to a dyno.

For example, instead of this:

PORT=8080
EXPOSE $PORT
CMD gunicorn --bind 0.0.0.0:$PORT wsgi

We ask that you do something like this:

CMD gunicorn --bind 0.0.0.0:$PORT wsgi
1 Like

You can kind of mentally model this as “Aspose and docker shouldn’t know about port 80 in any way. If the configuration says port 80 anywhere, and it’s not overriden by something else, it will not work.”

1 Like

@bmulhollandrecital

Thanks for sharing more details. We have logged a ticket WORDSCLOUD-1937 to further investigate your requirement and implement it accordingly. We will keep you updated about the issuer resolution progress.

Hi @tilal.ahmad,

As you know from previous discussions, we are trying to run this container in AWS Fargate. Fargate has a restriction that image containers cannot bind to ports below 1024 but the Aspose Words Cloud seems to be hardcoded to run at port 80. This is yet another stumbling block for us. Is there any update on WORDSCLOUD-1937?

Thanks
Mike.

1 Like

@MikeAshtonAJB

Thanks for your inquiry. Please note your above reported issue WORDSCLOUD-1937 is resolved. The fix will be available in the upcoming release Aspose.Words Cloud 22.10. We will notify you as soon as we release the new version.

1 Like

The issues you have found earlier (filed as WORDSCLOUD-1937) have been fixed in this update. This message was posted using Bugs notification tool by Ivanov_John

For anybody who may stumble across this thread, the port can be configured by adding a PORT environment variable when starting the container.

@tilal.ahmad - The Docker container has almost no usable documentation. Lots of the questions that I asked you about load balancers, scaling considerations, outbound traffic to your servers, backend filesystems and now the port number could be covered in a document to save you answering the questions. It will also give companies a bit more confidence to use the container because it will look like it’s actually been considered and is being used in real production environments. Every question that I have asked is a standard consideration that almost every organisation will have. But while I have you, thank you for finding answers to all of my questions and getting the blockers resolved. You’re a real asset to this forum!

1 Like

@MikeAshtonAJB

Thank you for your feedback, it will help us to improve the quality of our API/documentation. We will consider your suggestions and will update the documentation soon.