WordPress Docker File Management Guide¶
Container Name: repumanagement
WordPress Path: /var/www/html
1. Access WordPress Container¶
# Access running WordPress container
docker exec -it repumanagement bash
# If bash is not available
docker exec -it repumanagement sh
2. Navigate to WordPress Root¶
3. File Operations¶
Copy a File¶
# Copy file within container
cp /var/www/html/wp-config.php /var/www/html/wp-config.php.bak
# Copy directory recursively
cp -r /var/www/html/wp-content/plugins/my-plugin /var/www/html/wp-content/plugins/my-plugin-backup
Move / Rename a File¶
# Move file to another location
mv /var/www/html/oldfile.php /var/www/html/newlocation/oldfile.php
# Rename a file
mv /var/www/html/old-name.php /var/www/html/new-name.php
# Rename a directory (same command)
mv /var/www/html/wp-content/plugins/old-plugin-name /var/www/html/wp-content/plugins/new-plugin-name
Delete a File or Directory¶
# Delete a single file
rm /var/www/html/unwanted-file.php
# Delete a directory and all its contents
rm -rf /var/www/html/wp-content/plugins/plugin-name
# Delete a theme
rm -rf /var/www/html/wp-content/themes/theme-name
# Delete with confirmation prompt (safer)
rm -i /var/www/html/file.php
Create a File or Directory¶
# Create an empty file
touch /var/www/html/newfile.php
# Create a directory
mkdir /var/www/html/wp-content/uploads/custom-folder
# Create nested directories
mkdir -p /var/www/html/wp-content/uploads/2025/01/custom
Find Files¶
# Find by name
find /var/www/html -name "*.php"
# Find by name pattern (case-insensitive)
find /var/www/html -iname "wp-config*"
# Find files modified in last 7 days
find /var/www/html -mtime -7
# Find and list files larger than 10MB
find /var/www/html -size +10M -ls
4. Edit Files Inside Container¶
Install nano if not available:
Edit a file:
5. Transfer Files Between Host and Container¶
Upload File from Host to Container¶
Download File from Container to Host¶
Upload Entire Folder¶
6. Fix File Permissions¶
# Set correct ownership for Apache
chown -R www-data:www-data /var/www/html
# Set directory permissions
find /var/www/html -type d -exec chmod 755 {} \;
# Set file permissions
find /var/www/html -type f -exec chmod 644 {} \;
7. Backup WordPress Files¶
# Create backup archive inside container
docker exec repumanagement tar -czf /tmp/wp-backup.tar.gz /var/www/html
# Copy backup from container to host
docker cp repumanagement:/tmp/wp-backup.tar.gz ./wp-backup.tar.gz
8. Restore from Backup¶
# Copy backup to container
docker cp ./wp-backup.tar.gz repumanagement:/tmp/wp-backup.tar.gz
# Extract backup inside container
docker exec repumanagement tar -xzf /tmp/wp-backup.tar.gz -C /
9. Container Management¶
# Start container
docker start repumanagement
# Stop container
docker stop repumanagement
# Restart container
docker restart repumanagement
# View container logs
docker logs repumanagement
# View live logs (follow)
docker logs -f repumanagement
# View container status
docker ps -a
# View resource usage
docker stats repumanagement
# Remove container (must be stopped first)
docker rm repumanagement
# Remove container and volumes
docker rm -v repumanagement
10. Image Management¶
# List all images
docker images
# Pull latest WordPress image
docker pull wordpress:latest
# Remove an image
docker rmi wordpress:latest
# Remove unused images
docker image prune
11. Recommended Production Setup¶
Example docker-compose.yml:
version: '3.8'
services:
wordpress:
image: wordpress
container_name: repumanagement
ports:
- "8080:80"
volumes:
- ./wordpress:/var/www/html
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wpuser
WORDPRESS_DB_PASSWORD: wppassword
WORDPRESS_DB_NAME: wpdb
restart: unless-stopped
db:
image: mysql:8.0
container_name: repumanagement_db
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: wpdb
MYSQL_USER: wpuser
MYSQL_PASSWORD: wppassword
restart: unless-stopped
volumes:
db_data:
12. Security Tips¶
- Never use 777 permissions on files or directories
- Always back up before editing configuration files
- Use volume mounts instead of modifying container files directly
- Restart container after major configuration changes
- Avoid storing sensitive credentials in wp-config.php in plain text
- Use
.envfiles for environment variables in docker-compose
End of Documentation