aws fargate_在AWS Fargate中使用Docker部署Web应用程序

本文档介绍了如何将Web应用程序部署到AWS Fargate上,利用Docker容器化技术。通过AWS Fargate,可以轻松运行无服务器容器,无需管理底层基础设施。教程适用于熟悉Docker和想要在云端部署Java或Python应用的开发者。
摘要由CSDN通过智能技术生成

aws fargate

动机 (Motivation)

Docker is a fantastic tool to encapsulate and deploy applications in an easy and scalable way. Indeed, something I find myself doing very often is wrapping Python libraries into Docker images that I can later use as boilerplates for my projects.

Docker是一种出色的工具,可以轻松,可扩展地封装和部署应用程序。 确实,我发现自己经常做的事情是将Python库包装到Docker映像中,以后可以用作我的项目的样板。

In this post, I will illustrate how to register your Docker images in a container registry and how to deploy the containers in AWS using Fargate, a serverless compute engine designed to run containerized applications. Additionally, we will use Cloud Formation to deploy our stack in a programmatic way. Let’s get started!

在本文中,我将说明如何在容器注册表中注册Docker映像,以及如何使用Fargate(一种旨在运行容器化应用程序的无服务器计算引擎)在AWS中部署容器。 此外,我们将使用Cloud Formation以编程方式部署堆栈。 让我们开始吧!

在容器注册表中注册图像 (Register your images in a container registry)

Container registries are to Docker images what code repositories are to code. In a registry, you create image repositories to push and register your local images, you can store different versions of the same image, and other users can pull and update the image if they have access to the repo.

容器注册表对于Docker映像来说是代码存储库所要编码的代码。 在注册表中,您可以创建映像存储库来推送和注册本地映像,可以存储同一映像的不同版本,并且其他用户(如果他们可以访问该存储库)可以提取和更新该映像。

Now, let’s say you have developed locally an image that you want to deploy to the cloud. To do so, we would need to store our local image in a container registry from which it can be pulled and deployed. In this article, I will be using a fairly simple image that starts a web Python-Dash application on port 80.

现在,假设您已经在本地开发了要部署到云的映像。 为此,我们需要将本地映像存储在容器注册表中,以便从中进行部署和部署。 在本文中,我将使用一个相当简单的图像在端口80上启动Web Python-Dash应用程序。

We will use the ECR (Elastic Container Registry) to register our images. ECR is an AWS service, quite similar to DockerHub, to store Docker images. The first thing we have to do is creating a repository in ECR, we can use the AWS CLI as follows:

我们将使用ECR (弹性容器注册表)注册我们的图像。 ECR是一项与DockerHub非常相似的AWS服务,用于存储Docker映像。 我们要做的第一件事是在ECR中创建存储库,我们可以如下使用AWS CLI:

aws ecr create-repository \
--repository-name \
--image-scanning-configuration scanOnPush=
--region eu

You should be able to see the repository in the AWS management console

您应该能够在AWS管理控制台中查看存储库

Image for post

To push local images to our ECR repository we are required to authenticate our local Docker CLI into AWS:

要将本地映像推送到我们的ECR存储库,我们需要将本地Docker CLI验证到AWS:

aws ecr get-login-password --region region | docker login --username AWS --password-stdin acccount_id.dkr.ecr.region.amazonaws.com

Just replace the aws_account_id and region appropriately. You should see the message Login Succeeded in the terminal, which means our local Docker CLI is authenticated to interact with the ECR.

只需适当地替换aws_account_idregion 。 您应该在终端上看到“ Login Succeeded ”消息,这意味着我们的本地Docker CLI已通过身份验证,可以与ECR交互。

Let’s push now our local image to our brand new repository. To do so we must tag our image to point to the ECR repository:

现在让我们将本地图像推送到全新的存储库中。 为此,我们必须标记图像以指向ECR存储库:

docker tag image_id account_id.dkr.ecr.eu-central-1.amazonaws.com/dash-app:latest

Now we just have to push it to the ECR:

现在我们只需要将其推送到ECR:

docker push account_id.dkr.ecr.eu-central-1.amazonaws.com/dash-app:latest

You should see the pushed image in the AWS Console:

您应该在AWS控制台中看到推送的图像:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值