Docker on Windows Server 2016 TP4 Downloading git in container through powershell

夙愿已清 提交于 2021-01-05 12:43:38

问题


I have an angular UI and a nodejs api. I am currently running windows server 2016 TP4 in Azure.Here are the steps I go through:

  1. I am able to remote in, create images, create containers based off those images, and attach to those containers no problem.
  2. I pulled a nodejs image from docker: docker pull microsoft/node and then created a container from that image: docker run --name 'my_api_name' -it microsoft/node cmd
  3. That command takes me into the container via a windows command prompt. I type powershell which takes me into a powershell shell and i can run npm commands.

    My question is, how do I install git onto this container? I want to reach out to the repository holding my app, pull it down and run it in this container. I will eventually push this container image up to the docker registry so clients can pull it down and run it on their windows env.


回答1:


You can do it like this in admin shell:

iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
cinst -y git



回答2:


Ideally you wouldn't add git to the container and try to pull your repo into it (that will also get messy with credentials for private repos

You should do your source control management on your host and then build the source code into a container. It's not yet there for the Windows Dockerfiles, but the Linux ones have ONBUILD. It should be possible to replicate that for Windows.




回答3:


RUN @powershell iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))   
RUN cinst -y git

Refer: Unable to install git and python packages inside Windows container




回答4:


Solved this by downloading the "Portable" version of Git. Copying those files into the container and ***then running the post installation script provided by Git.

Find appropriate download here: https://git-scm.com/download/win

Inside docker file:

ADD Git64/ C:/Git/

WORKDIR C:/Git/

RUN %windir%\System32\cmd.exe "/K" C:\Git\post-install.bat



来源:https://stackoverflow.com/questions/36750554/docker-on-windows-server-2016-tp4-downloading-git-in-container-through-powershel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!