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
This commit is contained in:
committed by
Todd Chaffee
parent
6807d7a8b2
commit
83f50f10d4
@ -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 <loction of servers private key> <file to be transferred> <user>@host:<location where the file has to be transferred>
|
||||
|
||||
```
|
||||
|
||||
## 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 <loction of servers private key> <user>@<host>:<location of remote file> <location where the file has to be transferred>
|
||||
|
||||
```
|
||||
|
||||
## 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 <loction of servers private key> <user1>@<host1>:<location of remote file> <user2>@<host2>:<location where the file has to be transferred>
|
||||
|
||||
```
|
||||
|
||||
#### To move entire directory use -r option
|
@ -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 <container name> run --rm <command>
|
||||
|
||||
```
|
||||
|
||||
* Command to view logs of the container
|
||||
|
||||
```
|
||||
docker logs <container name>
|
||||
|
||||
```
|
||||
|
||||
* Command to remove all stopped containers
|
||||
|
||||
```
|
||||
docker container prune
|
||||
|
||||
```
|
||||
|
||||
#### More Information
|
||||
- [More commands for docker containers]
|
||||
(https://docs.docker.com/engine/reference/commandline/container/)
|
@ -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 = <your AWS acces key>
|
||||
AWS_SECRET_ACCESS_KEY = <your AWS secret key>
|
||||
AWS_STORAGE_BUCKET_NAME = <your AWS 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 = <your AWS acces key>
|
||||
AWS_SECRET_ACCESS_KEY = <your AWS secret key>
|
||||
AWS_STORAGE_BUCKET_NAME = <your AWS 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'
|
||||
|
||||
```
|
Reference in New Issue
Block a user