How to bake credential into docker image for git?
If your git provider supports ssh with public keys, I think the easiest way would be to switch to them. You would also not have to copy around your password.
You need to:
- add ssh client to your docker image
- generate an ssh key and copy it to the image. The
ssh-agent
part is not needed - register the key to the provider
Using SSH keys inside docker container
Turns out when using Ubuntu, the ssh_config isn't correct. You need to add
RUN echo " IdentityFile ~/.ssh/id_rsa" >> /etc/ssh/ssh_config
to your Dockerfile in order to get it to recognize your ssh key.
Clone private git repo with dockerfile
My key was password protected which was causing the problem, a working file is now listed below (for help of future googlers)
FROM ubuntu
MAINTAINER Luke Crooks "luke@pumalo.org"
# Update aptitude with new repo
RUN apt-get update
# Install software
RUN apt-get install -y git
# Make ssh dir
RUN mkdir /root/.ssh/
# Copy over private key, and set permissions
# Warning! Anyone who gets their hands on this image will be able
# to retrieve this private key file from the corresponding image layer
ADD id_rsa /root/.ssh/id_rsa
# Create known_hosts
RUN touch /root/.ssh/known_hosts
# Add bitbuckets key
RUN ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts
# Clone the conf files into the docker container
RUN git clone git@bitbucket.org:User/repo.git
Related Topics
Elf Header or Installation Issue with Bcrypt in Docker Container
How to Do 'Ret' Instruction from Code at _Start in MACos? Linux
Crontab Is Not Working on Amazon Ec2 Server
-Bash: /Usr/Bin/Yum: /Usr/Bin/Python: Bad Interpreter: No Such File or Directory
When to Use Pipes VS When to Use Shared Memory
How Is It Possible That Kill -9 for a Process on Linux Has No Effect
Remove Only Files in Directory on Linux Not Directories
Using Linux, How to Specify Which Ethernet Interface Data Is Transmitted On
Delete a Column from a Delimited File in Linux
Chrome Certificate Selection Appears Multiple Times
Best Way to Set Environment Variables in Calling Shell
Is Kernel Space Mapped into User Space on Linux X86
Linux/Bash, Using Ps -O to Get Process by Specific Name
Specify the from User When Sending Email Using the Mail Command