I have a deploy job in a jenkins docker container to deploy the application in docker tomcat container running in a port:8383 inside the jenkins container port 8080.
I can able to deploy the application successfully and start the server for the first time.
However if I want to redeploy the application , the deploy job fails as the port 8383 already allocated.
I want to check if docker tomcat container is already running , if it is running then I need to stop the tomcat container ,deploy the application and start it again.
How can I achieve this using shell script?
First, start your container with a name (using the
--name
flag). This will allow you to easily find this container later, when you want to redeploy it:Using the name, you can check if the container already exists, and then stop and delete it if it does (the shell script is off the top of my head, there are probably better ways to build this):
After that, re-create your container with the new image as before.