I'm using both docker and docker-compose to host what for the most part is a LAMP stack. I'd like to be able to use git inside one of my containers without it asking for my user.email and user.name on push after I build. Along with other things such as my push.default and branch settings. Is there any good way to have docker or docker-compose copy the results of git config --list
to a file in the container, which I can then use with my entrypoint to setup the git config.
Even if you are running your project on Docker, you can still access your git account inside Docker Containers. All you need to do is just install Git inside your Docker Container.
Docker provides a host network which lets containers share your host's networking stack. This approach means localhost inside a container resolves to the physical host, instead of the container itself.
Is there any good way to have docker or docker-compose copy the results of git config --list to a file in the container, which I can then use with my entrypoint to setup the git config.
You really needn't do that to reach your aims, there is a outbox solution:
For your host machine which run git, all the contents of git config --list
is stored in files:
git config --system
to configure them, they are stored in /etc/gitconfig
git config --global
to configure them, they are stored in ~/.gitconfig
So, you just need to mount the files to containers, then can reuse the git configure on host machine.
Something like follows, FYI.
If host use --global
to configure git:
docker run --rm -it -v ~/.gitconfig:/etc/gitconfig your_image_with_git git config --list
output: user.name=xxx
If host use --system
to configure git:
docker run --rm -it -v /etc/gitconfig:/etc/gitconfig your_image_with_git git config --list
output: user.name=yyy
For docker-compose
, you can just configure volumes
to define the mount.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With