Looking at the official Ruby image Docker page - the sample shows setting the WORKDIR /usr/src/app
.
Does anyone know why this specific path?
Namely is it ok to just have my app at root or in other words leave out WORKDIR? I know its recommend as per the documentation but I have some issues in it not creating a directory.
Just want to ensure there are no issues in dropping it. I tested my image otherwise and it works as expected.
Thanks.
The WORKDIR command is used to define the working directory of a Docker container at any given time. The command is specified in the Dockerfile. Any RUN , CMD , ADD , COPY , or ENTRYPOINT command will be executed in the specified working directory.
where /usr/src/app is the mount point within the container (different Docker images will assume the project's code is at different spots within the file system; be sure to verify).
According to the documentation: The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile. If the WORKDIR doesn't exist, it will be created even if it's not used in any subsequent Dockerfile instruction.
The default is indeed / as stated elsewhere. It is worth mentioning, though, that you will almost never be running from an empty docker image ( FROM scratch ), so the WORKDIR is likely set by the base image you're using.
The Linux Documentation project says this about /usr/src
/usr is shareable, read-only data.
Large software packages must not use a direct subdirectory under the /usr hierarchy
The 'linux' sub-directory holds the Linux kernel sources, header-files and documentation.
I'm not sure why they used that directory, and it's probably not harmful, but it also isn't necessarily the best place for a Ruby/Rails app. At the same time the location you place it doesn't entirely matter, but you do probably want to observe some rules:
~
(home) folder. This can cause problems if you have libraries that install by default to home, then you try and mount that directory and it overwrites things. Plus, you may end up with artifacts in there (.bash_profile, .config/, etc) that you don't want/
(root) so you don't risk overwriting a system directoryCreating an /app
directory is the most common pattern I've seen. You'll see in some CI/CD tools that they put your data into an /app
folder, so that's what I try to use for my Dockerfiles
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With