Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Keep always running Go http server app inside a Docker container

I have a Docker container that runs just a Go binary I created that is a http server with Gin framework. I don’t use any other Web Server, just Go’s internal http server. Inside my Dockerfile at the end of file I have this:

EXPOSE 80

CMD ["/home/project/microservices/backend/engine/cmd/main"]

I use docker-compose to run the container and restart: always for each container. And it works!

But my question is that, if the http server that I created fails due to programming error or something, It will restart? how can I check this? does Docker has tools for this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried go with Supervisord but it has some problems and I was not successful on running it.

I want a workaround to keep the http server inside container always running.

What can I do?

>Solution :

You can try killing the process from the host. Find the process id using something like

ps -aux | grep main

Then kill it using

sudo kill <process id>

Docker will then restart it. By using

docker ps

you should see that the ‘status’ has changed to something like Up 10 seconds.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading