Home > OS >  Keep always running Go http server app inside a Docker container
Keep always running Go http server app inside a Docker container

Time:06-21

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?

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?

CodePudding user response:

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.

  • Related