File Management
Accessing Files Inside Docker Containers
- Enter a Docker container:
- Using Bash (if available):
docker exec -it CONTAINER_ID bash - Using Shell (alternative):
docker exec -it CONTAINER_ID sh
- Using Bash (if available):
- List directory contents:
ls -al - Read a specific file:
cat FILE_NAME
Copying Files to a Server
- Copy a file to the server:
scp ./FILE_NAME root@URL:/tmp - Log in to the server and locate the file:
ssh root@URL cd /tmp ls -al
Copying Files to a Docker Container
- Copy a file from the server to a container:
docker cp ./FILE_NAME CONTAINER_ID:/tmp - Enter the container and locate the file:
- Using Bash:
docker exec -it CONTAINER_ID bash - Using Shell:
docker exec -it CONTAINER_ID sh - Navigate to the /tmp directory:
cd /tmp
Performing Database Operations
Importing a Database Dump
- Upload the dump file to the server:
scp ./DUMP_FILE root@URL:/tmp - Copy the dump file to the database container:
docker cp ./DUMP_FILE CONTAINER_ID:/tmp - Restore the database dump inside the container:
mongodump /tmp/DUMP_FILE
Modifying Database Content
Example: Updating a user's role to "admin":
- Log in to the server:
ssh root@URL - Find the database container:
docker ps - Enter the container:
docker exec -it CONTAINER_ID bash - Access the MongoDB CLI:
mongosh - Select the database:
use DB_NAME - Update the user's roles:
db.users.findOneAndUpdate( { email: "EMAIL" }, { $push: { roles: "admin" } } ) - Verify the changes:
db.users.find({ email: "EMAIL" })