在未登录的情况下在AWS EC2实例上部署Docker容器 [英] deploy docker container on AWS EC2 instance without being logged in

查看:242
本文介绍了在未登录的情况下在AWS EC2实例上部署Docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是微服务的初学者,并且已经花了数小时来研究当今AWS的最微小的痛苦,我会感谢任何专家的建议,因为我怀疑下一步非常小,否则可能要花我几个小时来解决.

I'm a beginner with microservices and have spent hours on the most tiny painful things of AWS today, would appreciate any expert advice as I suspect the next step is very small but could take me hours to work it out otherwise.

所以我先部署了一个nano实例,然后部署了ssh.实际上必须重做以修复安全组,但是无论如何它最终还是可以工作的.按照此处,总结来说,docker save是在本地镜像中创建一个.tar,而docker load在等待15分钟以上传scp之后将其远程放入系统中.然后在命令提示符下键入docker run.

So I deployed a nano instance then ssh into it. Had to actually redo it to fix the security group but anyway it worked eventually. Used scp to put my docker image up there per the instructions here, in summary docker save to make a .tar out of the image locally and docker load to put it into the system remotely after waiting 15 minutes for scp to upload. Then typed docker run at the command prompt.

之所以采取这些(linux)终端措施,是因为在过去3天中两次尝试从AWS控制台尝试执行失败,但都失败了,因为它已上传但无法运行.

Had resorted to these (linux) terminal measures as over the last 3 days had twice tried and failed to do it from the AWS console, as in it uploaded but wouldn't run.

现在,当我键入docker run my_image时,它运行得非常好,并且可以同时在其中使用docker imagesdocker ps -a命令查看它!

Now it runs fantastically when I type docker run my_image and I can see it in there with both the commands docker images and docker ps -a !

但是我的AWS实例运行时命令提示符很忙..如果我关闭终端窗口,它肯定会死.现在,我知道它可以在这里运行,如何部署"它,即让它运行并继续运行一个月或直到另行通知?我认为它可能需要某种称为任务定义"的json文件,但实际上根本不知道下一步该怎么做.可以在登录实例的终端中完成此任务定义和所有剩余任务吗?

But the command prompt on my AWS instance is busy while it runs.. if I close the terminal window it will surely die. Now that I know it works there, how can I 'deploy' it, ie let it run and continue to run for a month or until further notice? I think it might need some kind of json file called 'task definition' but don't really know at all what to do next. Can this task definition and all remaining tasks be done from within a terminal logged into the instance?

推荐答案

我发现一些错误:

  • 您应该使用Docker注册表服务而不是对映像进行SCPing.在AWS上有EC2容器注册表,或者您也可以使用Docker Hub.这将使将图像放到实例上变得更加容易.

  • You should use a Docker registry service instead of SCPing an image. On AWS there is EC2 Container Registry or you can also use Docker Hub as well. This will make it much easier to get your images onto your instances.

我不确定为什么无法使用控制台启动容器.我假设您正在使用AWS ECS?您可以尝试故障排除指南来帮助您找出原因您的任务没有运行.

I'm not sure why you weren't able to start your container using the console. I assume you are using AWS ECS? You might try the troubleshooting guide to help you figure out why your task wasn't running.

听起来您是在前台(附加到您的Shell)而不是在后台启动Docker容器.尝试在您的Docker运行中添加 -d标志命令在后台运行容器,以便您可以关闭SSH会话.请注意,如果容器内的应用程序崩溃,则容器仍将停止.这是使用诸如AWS ECS之类的协调器来定义将始终尝试运行一定数量任务的服务的原因之一. ECS还有助于将Docker容器放置到实例上并在后台自动为您启动它.

It sounds like you are starting a docker container in the foreground (attached to your shell) rather than in the background. Try adding the -d flag to your docker run command to run the container in the background so you can close your SSH session. Note that if the application process inside your container crashes the container will still stop. This is one reason for using an orchestrator such as AWS ECS to define a service that will attempt to always run a certain number of your tasks. ECS also helps with getting the docker container onto the instance and starting it for you in the background automatically.

这篇关于在未登录的情况下在AWS EC2实例上部署Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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