简体   繁体   English

如何在启动(AWS)时将数据从Docker容器复制到ECS?

[英]How to copy data from docker container to ECS on startup (AWS)?

I have two containers, one is web-server based on Node.JS with assets directory. 我有两个容器,一个是基于带有assets目录的Node.JS的Web服务器 Another container is nginx which proxify page requests to web-server and getting statics from assets directory. 另一个容器是nginx ,它代理对Web服务器的页面请求并从assets目录获取静态信息。

I created AWS cluster, EC2 instance, built and pushed docker images to registry, made tasks to deploy my applications, but I can't share with assets directory to nginx because directory is not part of this container. 我创建了AWS集群,EC2实例,构建了docker映像并将其推送到注册表,完成了部署应用程序的任务,但是我无法与assets目录共享到nginx,因为目录不属于此容器。

So to solve my problem I figured out to create EFS and attach the volume, add permissions to ec2-user and makes directory available by path /var/html/assets . 因此,为了解决我的问题,我想出了创建EFS并附加卷,为ec2-user添加权限并通过/var/html/assets路径使目录可用的方法。

Cool and how to copy assets content from my web-server docker container to /var/html/assets ? 酷,如何将资产内容从Web服务器Docker容器复制到 /var/html/assets

I want to make it public / shared because soon I will make additional servers which should also place assets to this common directory. 我想将其设为公开/共享,因为很快我将制作其他服务器,这些服务器也应将资产放置到此公共目录中。

The process should be automized and work on each deployment, guys, any suggestions? 这个过程应该自动化并且可以在每个部署上工作,伙计们,有什么建议吗? Thanks! 谢谢!

To copy assets content from your web-server docker container to your host machine, say you want to save your assets content from container to /var/html/assets on host machine, use this command to run your container: 要将资产内容从Web服务器docker容器复制到主机,例如,您要将资产内容从容器保存到主机上的/ var / html / assets,请使用以下命令运行容器:

docker run --name=nginx -d -v ~/var/html/assets:[Your Container path] -p 5000:80 nginx

-v ~/var/html/assets:[Your Container path] Sets up a bindmount volume that links [Your Container path] directory from inside the Nginx container to the ~/var/html/assets directory on the host machine. -v〜/ var / html / assets:[您的容器路径]设置一个绑定安装卷,该卷将Nginx容器内部的[您的容器路径]目录链接到主机上的〜/ var / html / assets目录。 Docker uses a : to split the host's path from the container path, and the host path always comes first. Docker使用:来将主机路径与容器路径分开,并且主机路径始终排在最前面。

Hope it will help! 希望对您有所帮助!

I solved problem by making host directory accessible for writing chmod 777 /var/html/assets , then added a volume which is looking to host directory and applied it to web and nginx containers. 我通过编写chmod 777 /var/html/assets使主机目录可访问来解决了问题,然后添加了一个用于查找主机目录的卷并将其应用于webnginx容器。 When running the web container, it invokes cp instruction to copy assets to mount directory (host directory). 运行web容器时,它将调用cp指令以将资产复制到安装目录(主机目录)。 Nginx will see populated directory and can use it. Nginx将看到填充的目录并可以使用它。

Note: It's a temporary / workaround solution, giving xrw access to directory is not a good way because of security. 注意: 这是一个临时/解决方法,由于安全性,授予xrw访问目录不是一个好方法。

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

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