> **CORRECTION (this lesson is `status: superseded`; do not follow its Ruby steps).**
CORRECTION (this lesson is
status: superseded; do not follow its Ruby steps). The Root Cause line for Issue 1 below is correct —require_relativeresolves against the file that contains the call — but the Issue 1 Solution (Steps 1–3:pwd,cdinto the script's directory, and theFile.expand_path(File.dirname(__FILE__), …)rewrite) is wrong and cannot repair the failure: acddoes not change a file-anchored lookup, and theFile.expand_pathform is semantically whatrequire_relativealready does. The corrected diagnosis and fix live inlessons/core/ruby-require-relative-resolves-against-the-requiring-file.md, which supersedes this lesson. The Docker port half of this lesson is unaffected and is covered bylessons/contrib/port-already-allocated-find-and-free-the-holder.md. This file is kept as-is for history; lessons are immutable once merged.
This lesson addresses two distinct but commonly encountered issues in development environments:
try.rb) fails during initialization with a LoadError indicating that require_relative cannot find the lib/tui directory. Ruby version and standalone code work fine, suggesting the issue is related to the script's working directory or path resolution.docker compose up fails with a port allocation error indicating that port 8080 is already in use on the host system.The require_relative directive in Ruby loads files relative to the file containing the directive, not relative to the current working directory. When the script is run from a different directory than where it's located, the relative path to lib/tui becomes invalid, causing the LoadError.
When a Docker stack is restarted, containers may not immediately release the host ports they were bound to. This can happen if the container process doesn't shut down cleanly or if there's a delay in releasing network resources. As a result, when attempting to restart the stack, Docker cannot bind to the already allocated port.
Before running the script, ensure you're in the correct directory:
pwdExecute the script from its containing directory:
cd /path/to/script/directory
ruby try.rbIf you need to run the script from other directories, modify it to use absolute paths or adjust the relative path:
# At the top of try.rb
require File.expand_path(File.join(File.dirname(__FILE__), 'lib', 'tui'))Find which process is using port 8080:
lsof -i :8080
# On Linux
sudo netstat -tulpn | grep :8080Kill the process that's holding the port:
# Using PID from previous command
kill -9 <PID>Remove any stopped containers and networks that might be holding resources:
docker-compose down -v --remove-orphans
docker system prune -fAfter implementing the solution, verify the script runs correctly:
cd <LOCAL_DIR> && ruby try.rbAfter resolving the port conflict, verify the stack starts successfully:
docker compose upCheck that the container is running and accessible on port 8080:
docker ps | grep -E '8080/tcp'docker-compose down before restarting to ensure clean resource release.require_relative vs require distinction is important: require searches in the load path while require_relative uses relative paths from the file's location.