scidash / docker-stacks

Docker stacks for SciDash projects.
0 stars 0 forks source link

How to invoke a docker shell instance, while passing in git config instructions first. #7

Closed russelljjarvis closed 7 years ago

russelljjarvis commented 7 years ago

General idea is like: cd ~/git/sciunitopt; sudo docker run -v `pwd`:/home/mnt -it deapscoop1 git config --global user.name "spam_me"; git config --global user.email "spam_box@asu.edu; bash"

russelljjarvis commented 7 years ago

The approach below is more likely to work, but something that can be converted into a one line docker config and run statement for a bash alias is preferable.

1 create a file with the commands to pass in:

$touch docker_config
$echo 'git config --global user.name "spam_me"; git config --global user.email "spam_box@asu.edu' >docker_config

2 start the container: $sudo docker run deapscoop1;

3 send the command to the container: docker exec -i deapscoop1 bash -c 'cat > ~/.bashrc' < docker_config

4 docker run -it deapsoop1 bash

TODO: Once an approach works, add it to the sciunitopt documentation.

russelljjarvis commented 7 years ago

Note: this hack seems to be working well ATM, however there should more elegant solution, if only I could more effectively form a search query of stack exchange.

Another solution is to make a BASH function that creates a wrapper version of the standard Dockerfile in a nested tmp directory, which is deleted after every run. Building and running should be separate functions but I have added them all there together.

#Hide Docker Wrapper: Personalize docker images by filling out credentials
#in a way that won't be commmitted to your public source code.
function hdrr {
    image_name=$pwd
    mkdir tmp
    cp Dockerfile tmp
    echo 'RUN git config --global user.name "spam_me"' >> Dockerfile
    echo 'RUN git config --global user.email "spam_box@some.edu; bash"' >> Dockerfile
    cd tmp; 
    #hopefully for you this only adding two simple lines to an already cached build
    sudo docker build -t $image_name .
    #change back into the base directory.
    cd ..
    sudo docker run -v `pwd`:/home/mnt -it $image_name bash;
    #delete tmp so there is no chance it will get added to GH source code 
    rm -r tmp
}
rgerkin commented 7 years ago

@russelljjarvis Could you just mount your $HOME/.gitconfig like this:
docker run -it -v $HOME/.gitconfig:/home/jovyan/.gitconfig scidash/scipy-notebook-plus bash You could even be bold and mount your $HOME/.ssh as well to try to get password-less interaction with GitHub.

russelljjarvis commented 7 years ago

Yes I think that would work