This documentation is part of the "Projects with Books" initiative at zenOSmosis.
The source code for this project is available on GitHub.
Command Reference
Relevant source files
This page provides a comprehensive reference for all commands used to build, run, manage, and interact with the sshfs-mac-docker system. Commands are organized by functional category for quick lookup during system operations.
For detailed explanations of how these commands fit into the overall workflow, see Getting Started. For troubleshooting command-related issues, see Troubleshooting.
Sources: README.md:1-90
Command Workflow Overview
Sources: README.md:19-86
Docker Image Management
Commands for building and managing the docker-sshfs image.
docker build
Builds the Docker image from the Dockerfile in the current directory.
| Component | Value |
|---|---|
| Syntax | docker build -t docker-sshfs . |
| Working Directory | Repository root (contains Dockerfile) |
| Tag Name | docker-sshfs |
| Context | . (current directory) |
| Build Time | ~1-2 minutes (downloads Ubuntu base + packages) |
Example:
What This Builds:
- Ubuntu base image with sshfs and samba packages
- User account
sshuser:sshpass(UID 1000, GID 1000) - Directory structure:
/remote,/samba-sharewith symbolic link - Configuration files:
smb.conf, modifiedfuse.conf
Sources: README.md:19-23
docker rmi
Removes the built image from the local Docker registry.
| Component | Value |
|---|---|
| Syntax | docker rmi docker-sshfs |
| When to Use | After removing all containers using this image |
| Effect | Deletes image, freeing disk space |
Example:
Sources: Referenced in state diagram (Diagram 6 in high-level overview)
Container Lifecycle Management
Commands for starting, stopping, and managing the container instance.
graph LR
Command["docker run"]
subgraph "Required_Flags"
Privileged["--privileged\nFUSE requires privileged mode"]
Name["--name docker-sshfs\nContainer identifier"]
Port139["-p 127.0.0.1:139:139\nNetBIOS port mapping"]
Port445["-p 127.0.0.1:445:445\nSMB port mapping"]
end
subgraph "Result"
Container["Container running\nsmbd in foreground"]
end
Command --> Privileged
Command --> Name
Command --> Port139
Command --> Port445
Privileged --> Container
Name --> Container
Port139 --> Container
Port445 --> Container
docker run
Starts a new container from the docker-sshfs image with required privileges and port mappings.
| Component | Value | Purpose |
|---|---|---|
| Full Command | docker run --privileged --name docker-sshfs -p 127.0.0.1:139:139 -p 127.0.0.1:445:445 docker-sshfs | Start container |
--privileged | Required | FUSE operations need elevated privileges |
--name | docker-sshfs | Container identifier for subsequent commands |
-p 127.0.0.1:139:139 | Port mapping | NetBIOS session service (localhost only) |
-p 127.0.0.1:445:445 | Port mapping | SMB over TCP (localhost only) |
| Process Mode | Foreground | Runs smbd -F as main process; container stops when smbd exits |
Example:
Important Notes:
- Container runs in foreground by default; terminal shows Samba logs
- Use
-dflag for detached mode:docker run -d --privileged ... - Port binding to
127.0.0.1prevents external network access - Container must be named
docker-sshfsor update container name in subsequent commands
Sources: README.md:26-34
docker stop
Stops a running container gracefully.
| Component | Value |
|---|---|
| Syntax | docker stop docker-sshfs |
| Effect | Sends SIGTERM to smbd, unmounts may fail if Finder still connected |
| Timeout | 10 seconds (default), then SIGKILL |
Example:
Sources: Implied by container lifecycle in README.md85
docker start
Restarts a stopped container (preserves SSHFS mounts if not explicitly unmounted).
| Component | Value |
|---|---|
| Syntax | docker start docker-sshfs |
| When to Use | After docker stop, to resume without rebuilding |
| Note | SSHFS mounts are not preserved across container restarts |
Example:
Sources: Container lifecycle management pattern
docker rm
Removes a stopped container permanently.
| Component | Value |
|---|---|
| Syntax | docker rm docker-sshfs |
| Prerequisite | Container must be stopped first |
| Effect | Deletes container and all internal state |
Example:
Sources: Standard Docker lifecycle pattern
Container Inspection
Commands for querying container state and metadata.
docker inspect
Retrieves detailed container metadata, most commonly used to get the container's IP address.
| Component | Value |
|---|---|
| Get IP Address | docker inspect --format '{{ .NetworkSettings.IPAddress }}' docker-sshfs |
| Full JSON Output | docker inspect docker-sshfs |
| Common Use Case | Find container IP for SMB connection from macOS |
Example - Get Container IP:
Output Example:
172.17.0.2
This IP address is used in Finder to connect: smb://172.17.0.2
Sources: README.md:57-61
docker logs
Views container output (Samba logs).
| Component | Value |
|---|---|
| Syntax | docker logs docker-sshfs |
| Follow Mode | docker logs -f docker-sshfs |
| Last N Lines | docker logs --tail 50 docker-sshfs |
Example:
Sources: Standard Docker logging pattern
docker ps
Lists running containers.
| Component | Value |
|---|---|
| Running Containers | docker ps |
| All Containers | docker ps -a |
| Filter by Name | docker ps -f name=docker-sshfs |
Example:
Sources: Standard Docker inspection pattern
SSHFS Operations
Commands executed inside the container to mount and unmount remote filesystems.
Entering the Container
Before executing SSHFS commands, access the container's interactive shell.
| Component | Value |
|---|---|
| Syntax | docker exec -it docker-sshfs bash |
| User | root (default exec user) |
| Working Directory | / (container root) |
Example:
You will see a shell prompt like:
root@a1b2c3d4e5f6:/#
Sources: README.md:38-44
sshfs Mount Command
Mounts a remote filesystem via SSH to /remote inside the container.
| Component | Value | Purpose |
|---|---|---|
| Full Syntax | sshfs -o allow_other,uid=1000,gid=1000 user@host:path /remote | Mount remote filesystem |
-o allow_other | Critical | Without this, Samba cannot access the mount (different user) |
-o uid=1000 | Critical for writes | Sets file ownership to sshuser (UID 1000) |
-o gid=1000 | Critical for writes | Sets group ownership to sshuser (GID 1000) |
user@host:path | Variable | SSH connection string; replace with actual remote endpoint |
/remote | Fixed | Mount point directory (pre-created in container) |
Examples:
Why These Options Matter:
| Option | Without It | With It |
|---|---|---|
allow_other | Samba (running as sshuser) cannot access files | Samba can read/write mounted files |
uid=1000 | Files owned by root or remote UID | Files owned by sshuser, enabling writes |
gid=1000 | Group ownership mismatch | Consistent group ownership |
Sources: README.md:46-53
Additional SSHFS Options
Optional parameters for advanced use cases.
| Option | Purpose | Example |
|---|---|---|
-o port=N | Custom SSH port | -o port=2222 |
-o IdentityFile=/path/to/key | Use specific SSH key | -o IdentityFile=/root/.ssh/id_rsa |
-o reconnect | Auto-reconnect on connection loss | -o reconnect |
-o ServerAliveInterval=15 | Keep connection alive | -o ServerAliveInterval=15 |
-o Compression=yes | Enable SSH compression | -o Compression=yes |
Combined Example:
Sources: Standard SSHFS options (not explicitly in README but commonly used)
fusermount Unmount Command
Unmounts the SSHFS filesystem from /remote.
| Component | Value |
|---|---|
| Syntax | fusermount -u /remote |
| When to Use | Before stopping container or remounting different endpoint |
| Common Error | Device or resource busy (see below) |
Example:
Handling "Device or resource busy" Error:
Cause: macOS Finder still has an active SMB connection to the share.
Solution:
- In macOS Finder, eject the network share (right-click → Eject)
- Then retry:
fusermount -u /remote - Alternative:
docker stop docker-sshfs(forces unmount)
Sources: README.md:72-85
macOS Client Operations
Commands and procedures executed on the macOS host to connect to the Samba share.
Discovering Container IP
Since localhost does not work for SMB connections, the container's internal Docker IP must be used.
Command:
Expected Output:
172.17.0.2
Sources: README.md:57-61
Connecting from Finder
Procedure:
-
In macOS Finder, press
Cmd+Kor navigate toGo → Connect to Server -
Enter the connection string using the container IP:
smb://172.17.0.2
Replace 172.17.0.2 with the actual container IP from docker inspect
-
Click Connect
-
Authentication prompt:
- Select Guest (do not use username/password)
- Click Connect
-
The share appears in Finder under Network → IP address
-
Inside the share, navigate to the
remotedirectory to access mounted files
Sources: README.md:55-69
Connection String Format
| Component | Format | Example |
|---|---|---|
| Protocol | smb:// | Required |
| IP Address | Container IP (not localhost) | 172.17.0.2 |
| Port | Implicit (139/445) | Not specified in URL |
| Full String | smb://<container-ip> | smb://172.17.0.2 |
Why localhost doesn't work: Despite port forwarding to 127.0.0.1, the macOS SMB client requires connection to the container's internal IP address due to how Docker's network stack handles SMB protocol translation.
Sources: README.md57
Disconnecting from macOS
Procedure:
- In Finder, locate the mounted share under Network
- Right-click (or Control-click) on the share
- Select Eject or click the eject button (⏏)
- Share disappears from Finder
Alternative: Drag the share icon to Trash
Effect: Closes SMB connection, allowing safe unmounting with fusermount -u in the container
Sources: README.md85
Command Sequences for Common Tasks
Complete Setup and Mount
Sources: README.md:19-69
Complete Teardown
Sources: README.md:72-85
Remounting Different Remote Endpoint
Sources: Implied workflow from README.md:46-85
State-Based Command Reference
Sources: README.md:19-85
Quick Reference Table
| Task | Command | Location |
|---|---|---|
| Build image | docker build -t docker-sshfs . | Repository root |
| Start container | docker run --privileged --name docker-sshfs -p 127.0.0.1:139:139 -p 127.0.0.1:445:445 docker-sshfs | macOS host |
| Get container IP | docker inspect --format '{{ .NetworkSettings.IPAddress }}' docker-sshfs | macOS host |
| Enter container | docker exec -it docker-sshfs bash | macOS host |
| Mount remote | sshfs -o allow_other,uid=1000,gid=1000 user@host:path /remote | Inside container |
| Unmount remote | fusermount -u /remote | Inside container |
| Connect in Finder | smb://container-ip | macOS Finder |
| Stop container | docker stop docker-sshfs | macOS host |
| View logs | docker logs docker-sshfs | macOS host |
| Remove container | docker rm docker-sshfs | macOS host |
| Remove image | docker rmi docker-sshfs | macOS host |
Sources: README.md:19-90