File Management

Accessing Files Inside Docker Containers

  1. Enter a Docker container:
    • Using Bash (if available):
      docker exec -it CONTAINER_ID bash
      
    • Using Shell (alternative):
      docker exec -it CONTAINER_ID sh
      
  2. List directory contents:
    ls -al
    
  3. Read a specific file:
    cat FILE_NAME
    

Copying Files to a Server

  1. Copy a file to the server:
    scp ./FILE_NAME root@URL:/tmp
    
  2. Log in to the server and locate the file:
    ssh root@URL
    cd /tmp
    ls -al
    

Copying Files to a Docker Container

  1. Copy a file from the server to a container:
    docker cp ./FILE_NAME CONTAINER_ID:/tmp
    
  2. 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

  1. Upload the dump file to the server:
    scp ./DUMP_FILE root@URL:/tmp
    
  2. Copy the dump file to the database container:
    docker cp ./DUMP_FILE CONTAINER_ID:/tmp
    
  3. Restore the database dump inside the container:
    mongodump /tmp/DUMP_FILE
    

Modifying Database Content

Example: Updating a user's role to "admin":

  1. Log in to the server:
    ssh root@URL
    
  2. Find the database container:
    docker ps
    
  3. Enter the container:
    docker exec -it CONTAINER_ID bash
    
  4. Access the MongoDB CLI:
    mongosh
    
  5. Select the database:
    use DB_NAME
    
  6. Update the user's roles:
    db.users.findOneAndUpdate(
    { email: "EMAIL" },
    { $push: { roles: "admin" } }
    )
    
  7. Verify the changes:
    db.users.find({ email: "EMAIL" })