简体   繁体   中英

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. Another container is nginx which proxify page requests to web-server and getting statics from assets directory.

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.

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 .

Cool and how to copy assets content from my web-server docker container to /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:

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. Docker uses a : to split the host's path from the container path, and the host path always comes first.

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. When running the web container, it invokes cp instruction to copy assets to mount directory (host directory). Nginx will see populated directory and can use it.

Note: It's a temporary / workaround solution, giving xrw access to directory is not a good way because of security.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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