Starting Prolog http server trough docker

I’m using: SWI-Prolog version 64 bits, version 8.1.16-22

I want to deploy my Prolog http server as a docker container. I have created a main.pl script, which loads all dependencies and predicates and starts prolog http server. When I do it locally it works fine. When I am trying to do it trough docker, it starts and it loads everything successfully, but when it runs trough all the lines it just exits with code(0), I was wondering is there a proper way to start a prolog script from terminal? So it would not exit when it runs trough code?

:- set_setting(http:cors, [*]).
server(Port) :-
	get_base_location_atom(Base),
	atom_concat(Base, '/cert/server.pem', Server),
	atom_concat(Base, '/cert/private_key.pem', PrivateKey),
    http_server(http_dispatch,
                        [ port(Port),
                      ssl([ certificate_file(Server),
                            key_file(PrivateKey),
                            password("XXXXXXXXXXXX"),
                            peer_cert(false)
                          ])
                    ]).
CMD [ "/root/bin/swipl", "main.pl" ]

Added infinite loop with sleep, that solved the issue for now.

Later will look into how this script can be run as a daemon.

That is a solution. I typically use thread_get_message/1 to block. That also allows you to send something to this queue and make the main thread do something (or stop).

1 Like

I found

ENTRYPOINT [“swipl”]
CMD ["/app/server.pl", “–user=daemon”, “–fork=false”, “–port=8888”]

Please check

https://gitlab.com/matteo.redaelli/prolog-http-server-docker

1 Like