Search code examples
laraveldockerdockerfilelaravel-sail

Add to PATH from Laravel Sail Dockerfile


I'm trying to add sqlpackage to a Laravel Sail Docker. While this is normally not really difficult, Sail makes it kinda hard.

I have the following section in my Dockerfile

RUN curl -L https://go.microsoft.com/fwlink/?linkid=2157202 -o /usr/local/bin/sqlpackage.zip
RUN mkdir /usr/local/bin/sqlpackage
RUN unzip /usr/local/bin/sqlpackage.zip -d /usr/local/bin/sqlpackage
RUN rm /usr/local/bin/sqlpackage.zip
RUN echo "export PATH=\"\$PATH:$HOME/usr/local/bin/sqlpackage\"" >> /home/sail/.bashrc
RUN chmod a+x /usr/local/bin/sqlpackage/sqlpackage

First off, I'm not happy with the install path I've chosen (/usr/local/bin). But it's the best I could think of. Any suggestions are welcome.

My second, and more important issue is that I can't add run the echo to the path when installing. The install script can't reach the home path. Would really like a solution for this. But I get this error:

cannot create /home/sail/.bashrc: Directory nonexistent

However it exists. So it's a rights issue for the installing user. Any suggestions are welcome.


Solution

  • cannot create /home/sail/.bashrc: Directory nonexistent

    It looks like user sail doesn't exist so

    before

    RUN echo "export PATH=\"\$PATH:$HOME/usr/local/bin/sqlpackage\"" >> /home/sail/.bashrc
    

    Create user like below

    # add user
    RUN useradd sail
    
    # and then
    RUN echo "export PATH=\"\$PATH:/usr/local/bin/sqlpackage\"" >> /home/sail/.bashrc
    

    Also $HOME is not required, because during build time it become export PATH="$PATH:/root/usr/local/bin/sqlpackage"

    Try below on terminal ( for example I am as root user ):

    $ echo "export PATH=\"\$PATH:$HOME/usr/local/bin/sqlpackage\"" 
    export PATH="$PATH:/root/usr/local/bin/sqlpackage"
    
    

    Similar way during build process it will use current user that is root.

    First off, I'm not happy with the install path I've chosen (/usr/local/bin). But it's the best I could think of. Any suggestions are welcome.

    /usr/local/bin is the location for all add-on executables that you add to the system to be used as common system files by all users. Locally installed software must be placed within /usr/local.

    # Used for non-system libraries and executables
    /usr/local/bin
    

    usr stands for User System Resources. This is the location that system programs and libraries are stored.

    local represents resources that were not shipped with the standard distribution and, usually, compiled and maintained on a per site basis.

    bin represents binary compiled executables.

    So keep in mind these three

    • /usr/bin: User commands.
    • /usr/sbin: System administration commands.
    • /usr/local/bin: Locally customized software.

    /opt is a directory for installing unbundled packages that is packages not part of the Operating System distribution, but provided by an independent source. I usually put all 3rd party packages in /opt