Issue
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.
Solution
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:
- If use
git config --system
to configure them, they are stored in/etc/gitconfig
- If use
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.
Answered By - atline Answer Checked By - Cary Denson (WPSolving Admin)