Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy code from localhost to docker containers using Git?

Tags:

git

docker

I am new to docker(2 days) and really trying to understand how I can integrate it in my development workflow.

Consider this situation (yes, I made this picture)
enter image description here

I am continuously working on my local git repo and want to test my code in one(or more) docker containers.

Question

a.) What is the best way recommended to get the code locally to these containers.

The reason I asked is because if I have to git commit-push locally and pull in respective containers, I see 2 problems upfront with that

1.) The rounds trip time in development is costly
2.) What if I am not in state to check-in my code, I am just testing/reproducing a bug etc.

Pardon my ignorance and please enlighten me with your ideas
Thanks

like image 328
daydreamer Avatar asked Mar 13 '26 21:03

daydreamer


1 Answers

For (2), that's what Git branches are for. If (1) is really a deal-breaker, and if Docker is running on the same machine that you're doing your development on (it's not clear whether that's the case), you can mount the local directory containing your code into a new Docker container with:

docker run -v /local/path/to/code:/path/inside/container/where/code/will/be --other-options imagename

This way, the directory will exist on both your local machine and in the Docker container at the same time (with changes at either end automatically showing up in the other), and you can operate on the directory's contents directly within Docker.

like image 99
jwodder Avatar answered Mar 15 '26 15:03

jwodder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!