I am running production code within an active docker container. I would like to use the Gitlab CI tool to auto deploy changes to the production environment WITHIN the docker container.

I am having trouble finding a clean way to do this.

One idea I have is to simply log into the docker container as part of the gitlab-ci automation script

  • docker exec -it 82jf72h8dj2 bash
  • then git pull from the appropriate directory

In theory, this will work... but what happens when the docker ID changes? Is there any way to detect this as part of the script? I would hate to have to keep updating the CICD variable since the docker ID seems to change fairly often...

  • 1
    in theory this could work, but its a bad solution. you should build a new image from your codebase and then update it on your production environment and restart it. Nov 5, 2020 at 11:31

1 Answer 1


The image acts as a foundation for each container that you start from it.

You might do the update in your 'fashion' way, but containers are ephemeral - let's say it got restarted, you updates are lost and you are back to the previous version.

If you want to handle this process by yourself, how would you track your versions ? Essentially you would have a root docker image and after that it would be so hard to know which version is currently running ? Could you also safely roll-back version to version ? How about if somebody hijacks you container, due to some Unix Socket permissions with the Docker daemon ...

What I am trying to say, do not rediscover the wheel :)

Take advantage of modern technologies like Kubernetes, deploy each image for a new version there, you have a roll - out deployment, readiness probes and so on ... You would be safe that your software is always working, track the versions and have H/A.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.