From 83f50f10d4490b5805288cbdb9bbfb8d45695aa4 Mon Sep 17 00:00:00 2001 From: Sindhuri1706 <35066155+Sindhuri1706@users.noreply.github.com> Date: Thu, 18 Oct 2018 00:05:13 +0530 Subject: [PATCH] Docker:More About Docker containers (#19018) * added intorduction to setup AWS S3 in Django project to store static assets and media files * added guidelines to move files between servers * added more commands for docker-containers --- .../ssh/moving-files-between-servers/index.md | 38 ++++++++++++ .../docker/More-about-containers/index.md | 44 +++++++++++++ .../index.md | 61 +++++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 client/src/guide/english/ssh/moving-files-between-servers/index.md create mode 100644 client/src/pages/guide/english/containers/docker/More-about-containers/index.md create mode 100644 client/src/pages/guide/english/miscellaneous/guide-to-store-media-files-of-django-app-to-aws-s3/index.md diff --git a/client/src/guide/english/ssh/moving-files-between-servers/index.md b/client/src/guide/english/ssh/moving-files-between-servers/index.md new file mode 100644 index 0000000000..15ae645b54 --- /dev/null +++ b/client/src/guide/english/ssh/moving-files-between-servers/index.md @@ -0,0 +1,38 @@ +--- +title: Moving files between servers +--- + +## Moving file from local computer to remote server + +* First add public key of remote server to known hosts + +* The command to copy files from local computer to remote server is + +``` + scp -i @host: + +``` + +## Moving file from remote server to local computer + +* First add public key of remote server to known hosts + +* The command to copy files from remote server to local computer is + +``` + scp -i @: + +``` + +## Moving file between remote servers + +* First add public key of remote servers to known hosts + +* The command to copy files between remote server to local computer is + +``` + scp -i @: @: + +``` + +#### To move entire directory use -r option \ No newline at end of file diff --git a/client/src/pages/guide/english/containers/docker/More-about-containers/index.md b/client/src/pages/guide/english/containers/docker/More-about-containers/index.md new file mode 100644 index 0000000000..19bf7d6940 --- /dev/null +++ b/client/src/pages/guide/english/containers/docker/More-about-containers/index.md @@ -0,0 +1,44 @@ +--- +title: More About Docker Containers +--- + +## More Commands to manage Docker Containers + +* Command to list Running Containers + +``` +docker conatiner ls + +``` + +* Command to list all the containers (including the stopped containers) + +``` +docker container ls -a + +``` + +* Command to execute command in the container + +``` +docker exec -it run --rm + +``` + +* Command to view logs of the container + +``` +docker logs + +``` + +* Command to remove all stopped containers + +``` +docker container prune + +``` + +#### More Information +- [More commands for docker containers] +(https://docs.docker.com/engine/reference/commandline/container/) \ No newline at end of file diff --git a/client/src/pages/guide/english/miscellaneous/guide-to-store-media-files-of-django-app-to-aws-s3/index.md b/client/src/pages/guide/english/miscellaneous/guide-to-store-media-files-of-django-app-to-aws-s3/index.md new file mode 100644 index 0000000000..4422103dc6 --- /dev/null +++ b/client/src/pages/guide/english/miscellaneous/guide-to-store-media-files-of-django-app-to-aws-s3/index.md @@ -0,0 +1,61 @@ +--- +title: Django-file-storage +--- +## Django Media Files and Static files Storage + +#### Steps to create AWS S3 Bucket + +* Open aws console and create IAM user for S3 bucket +* In services select S3 +* Create new S3 buket in S3 console + +#### Steps to do in django app + +* install boto3 and Django-storages libraries. The commands to install these libraries are + +``` +pip install boto3 +pip install django-storages +``` +* Add storages to Installed Apps in ```settings.py``` + +* To work with satic assets only you have to add the following to your settings.py + +``` +AWS_ACCESS_KEY_ID = +AWS_SECRET_ACCESS_KEY = +AWS_STORAGE_BUCKET_NAME = +AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME +AWS_S3_OBJECT_PARAMETERS = { + 'CacheControl': 'max-age=86400', +} +AWS_LOCATION = 'static' + +STATICFILES_DIRS = [ + os.path.join(BASE_DIR, 'mysite/static'), +] +STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION) +STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' + +``` +* To work with both static and media assets you have to add the following to your settings.py + +``` +AWS_ACCESS_KEY_ID = +AWS_SECRET_ACCESS_KEY = +AWS_STORAGE_BUCKET_NAME = +AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME +AWS_S3_OBJECT_PARAMETERS = { + 'CacheControl': 'max-age=86400', +} +AWS_LOCATION = 'static' + +STATICFILES_DIRS = [ + os.path.join(BASE_DIR, 'mysite/static'), +] +STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION) +STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' + +DEFAULT_FILE_STORAGE = 'mysite.storage_backends.MediaStorage' + +``` \ No newline at end of file