简体   繁体   English

使用Docker在生产中部署Go Service

[英]Deploy Go Service in production with Docker

I'm working on a Go service with Docker, and thinking that as it is compiled, to deploy code in production, I just need the docker compose, and the Docker image published on my registry. 我正在使用Docker开发Go服务,并认为在编译该代码以将代码部署到生产环境中时,我只需要docker compose,并将Docker映像发布在我的注册表中即可。

As I come from PHP world, I am used to clone my whole project to deploy it. 当我来自PHP世界时,我习惯于克隆整个项目以进行部署。

Is there any way I could deploy my project only with docker-compose file ? 有什么办法可以仅通过docker-compose file部署项目吗?

I saw on this post that I can git clone only a single file, but it feels that it is not a good way to do, what is the best practice to deploy a Go Microservice with Docker ? 我在这篇文章中看到我只能git clone一个文件,但感觉这不是一个好方法,用Docker部署Go Microservice的最佳实践是什么?

There are two separate problems in your question, and I am not sure which ones you're looking for an answer for. 您的问题有两个独立的问题,我不确定您要寻找的答案。

Q1: What's a good way to create a Dockerfile for my Go project A1: Have a look at the example here: https://docs.docker.com/develop/develop-images/multistage-build/ . 问题1:为Go项目创建Dockerfile的好方法是什么?问题1:在此处查看示例: https ://docs.docker.com/develop/develop-images/multistage-build/。 If you need to git clone, clone the entire source tree, as you would with php... 如果您需要git clone,请像使用php一样克隆整个源代码树。

Q2: Now that I have my image, how do I use it in production. Q2:现在我有了我的图像,如何在生产中使用它。 A2: Make sure it's available on a repository (public or private) somewhere. 解答2:请确保该文件在某个地方(公共或私有)的存储库中可用。 Then reference that image (using it's full name, which includes the FQDN of the repo server, if you aren't using Docker Hub) when starting your container. 然后在启动容器时引用该映像(使用全名,如果不使用Docker Hub,则使用全名,包括回购服务器的FQDN)。 There's no need to "git clone" anything at this point... 此时无需“ git clone”任何东西...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM