如何使用Git将代码从本地主机部署到Docker容器? [英] How to deploy code from localhost to docker containers using Git?

查看:502
本文介绍了如何使用Git将代码从本地主机部署到Docker容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是docker的新手(2天),并且确实试图了解如何将其集成到我的开发工作流程中。

I am new to docker(2 days) and really trying to understand how I can integrate it in my development workflow.

考虑这种情况(是的,我拍了这张照片)

Consider this situation (yes, I made this picture)

我一直在本地git repo上工作,并想在一个(或多个)docker中测试我的代码容器。

I am continuously working on my local git repo and want to test my code in one(or more) docker containers.

问题

a。)推荐的最佳方法是这些容器本地编码。

a.) What is the best way recommended to get the code locally to these containers.

我问的原因是因为如果我必须在本地git commit-push并拉入相应的容器,我会在前面看到2个问题

The reason I asked is because if I have to git commit-push locally and pull in respective containers, I see 2 problems upfront with that

1。)开发中的往返时间成本很高

2.)如果我不处于检入状态的状态,我只是在测试/复制一个错误等

1.) The rounds trip time in development is costly
2.) What if I am not in state to check-in my code, I am just testing/reproducing a bug etc.

请原谅我的无知,请启发您的想法

Pardon my ignorance and please enlighten me with your ideas
Thanks

推荐答案

对于(2),这就是Git分支的用途。如果(1)确实是一个破坏交易的事情,并且如果Docker在您进行开发的同一台计算机上运行(目前尚不清楚),则可以将包含代码的本地目录挂载到新目录中Docker容器,其中:

For (2), that's what Git branches are for. If (1) is really a deal-breaker, and if Docker is running on the same machine that you're doing your development on (it's not clear whether that's the case), you can mount the local directory containing your code into a new Docker container with:

docker run -v /local/path/to/code:/path/inside/container/where/code/will/be --other-options imagename

这样,目录将同时存在于您的本地计算机和Docker容器同时显示(两端的更改会自动显示在另一端),您可以直接在Docker中操作目录的内容。

This way, the directory will exist on both your local machine and in the Docker container at the same time (with changes at either end automatically showing up in the other), and you can operate on the directory's contents directly within Docker.

这篇关于如何使用Git将代码从本地主机部署到Docker容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆