I’ve read the following guide from Travis:
However, this does not fit my use case. I publish my Docker images to Docker hub for others to use. So, I don’t want to publish my Docker image to Docker hub in the build/test stage of my Travis run because I want to make sure that the tests pass first, otherwise, I might push a broken build. I don’t really understand the article because I’m not sure why someone would want to push an image before they run their tests. Also, what if the image that you are pushing to Docker hub gets updated somehow after the build/test stage and before the push to Docker hub stage? It just seems like there are a lot of problems with the approach shown in the article.
Is there any way to share the local Docker image between stages? I can run my tests inside the image. That is why I would like to share the image between stages. Otherwise, I have to re-build the image for each stage. I would build the image once and then run the tests inside it and if they pass then go on to the deployment phase which would push the same image to Docker Hub.
Is there a better way to do what I’m trying to do?