Mac OS环境下Docker的/usr/src/app路径配置疑问
Great question—let’s clear up the confusion around container vs. host system paths here!
First, a key point: the /usr/src/app path in your Docker command refers to a directory inside the Docker container, not your Mac (or Windows) host system. This path isn’t tied to any specific OS on your host; it’s defined by the official Rails Docker image you’re using.
Let’s break down what’s happening in that command:
-v "$PWD":/usr/src/app: This mounts your host’s current working directory ($PWD) to the/usr/src/appdirectory inside the container. Any changes made inside the container’s/usr/src/appwill sync back to your host’s current folder.-w /usr/src/app: This sets the container’s working directory to/usr/src/app, so therails newcommand runs directly in that container directory (which is mapped to your host’s current folder).- The official Rails Docker image is configured with
/usr/src/appas its default working directory (you can confirm this by runningdocker inspect rails | grep WORKDIRif you want to verify).
You don’t need to create an app directory under /usr/local/ on your Mac. The /usr/local/ path is part of your host’s filesystem, but it has no connection to the container’s internal /usr/src/app path. When you run that command, the rails new output will be saved directly to whatever directory you’re in on your Mac (since $PWD points to your current host folder).
To put it simply: the container’s path structure is independent of your host’s. You just need to make sure you run the command from the folder on your Mac where you want the new Rails app to live, and Docker handles the rest of the path mapping.
内容的提问来源于stack exchange,提问作者Steven Aguilar

