- Date:* 05/08/2025
**Steps to Deploy:**
1️⃣ Login to the NAS
-
Use SSH to access the NAS:
ssh username@nas_ip
2️⃣ Build the Docker Container
-
Navigate to the app's directory on the NAS:
cd /path/to/your/app -
Build the Docker image:
docker build -t myapp-image .
3️⃣ Start the Docker Container
-
Run the container and expose the necessary ports:
docker run -d --name myapp-container -p 8080:8080 myapp-image
4️⃣ Expose the Port in the Docker Network
-
Verify that the port 8080 is mapped and accessible inside the NAS:
docker port myapp-container -
Check connectivity from NAS to the Docker container:
curl http://localhost:8080
5️⃣ Configure the Web Server Application on the NAS In Web Portal Settings, select configure new settings
-
Open the Web Server App interface on your NAS.
-
Add a Reverse Proxy or Port Forwarding entry:
- Source Port: 8080
- Destination IP:
localhostor the Docker container IP - Destination Port: 8080
-
Ensure the web server points correctly to the Docker container.
Quick Commands Reference
- Login to NAS:
ssh username@nas_ip - Build Docker Image:
docker build -t myapp-image . - Run Docker Container:
docker run -d --name myapp-container -p 8080:8080 myapp-image - Check Docker Ports:
docker port myapp-container - Test Port Access:
curl http://localhost:8080
Checklist Before Deployment
- Dockerfile configured properly
- Port mapped correctly in Docker
- NAS Web Server App proxy configured
- Test connection from NAS web server to container
🚩 Troubleshooting Tips
| Problem | Possible Cause | Solution |
|---|---|---|
| Cannot access the app from the NAS | Port mapping issue or firewall restriction | Check Docker port mapping: docker port myapp-container and NAS firewall settings. |
curl http://localhost:8080 fails |
Container not running or wrong port | Run docker ps to check the container status. Make sure it exposes 8080. |
| Web server not reaching the container | Incorrect IP or reverse proxy settings | Use Docker IP with docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' myapp-container. |
| Docker container exits unexpectedly | Crash inside the app or bad Dockerfile | Run docker logs myapp-container to view error messages. |
| Port already in use | Conflict with another service | Find the process with sudo lsof -i :8080 and kill if necessary. |
| Changes not visible after redeploy | Old image still running | Stop and remove old container: docker rm -f myapp-container, then restart. |
| Network bridge issues | Docker network misconfiguration | Restart Docker networking: sudo systemctl restart docker. |
🔄 Common Docker Commands
| Command | Description |
|---|---|
docker ps
|
List all running containers |
docker ps -a
|
List all containers (running and stopped) |
docker images
|
List all Docker images |
docker logs
|
View logs for a specific container |
docker stop
|
Stop a running container |
docker start
|
Start a stopped container |
docker restart
|
Restart a running container |
docker rm
|
Remove a stopped container |
docker rmi
|
Remove a Docker image |
docker exec -it
|
Access the container's shell for debugging |
docker inspect
|
View detailed information about a container |
docker network ls
|
List all Docker networks |
docker network inspect
|
Inspect a Docker network |
docker system prune
|
Remove all stopped containers, unused networks, and dangling images |
docker volume ls
|
List all Docker volumes |
docker volume prune
|
Remove unused Docker volumes |
🌐 Networking Tips for Docker Containers
1️⃣ Accessing Container from Another Device on the Network
-
If you want to access the container from another device, use the NAS IP address and the exposed port:
http://nas_ip:8080 -
Ensure your NAS firewall allows the port (e.g., 8080).
2️⃣ Linking Containers Together (Legacy Method)
-
To link containers during
docker run:docker run --name container1 --link container2:alias_name -d myapp-image -
Inside
container1, you can accesscontainer2by the hostnamealias_name.
3️⃣ Docker Networks (Preferred Method)
-
Create a Docker network:
docker network create myapp-network -
Run containers on the same network:
docker run --network myapp-network --name backend -d backend-image docker run --network myapp-network --name frontend -d frontend-image -
Containers can communicate using container names:
curl http://backend:8080
4️⃣ Bridge vs Host Network Modes
-
Bridge Mode (default): Isolated networking, port mappings required.
-
Host Mode: Directly uses the host's network stack. Run with:
docker run --network host -d myapp-image