1

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.

Matt
  • 1,081
  • 15
  • 27
  • 1
    are you sure /home/sail exists ? if not create such user `RUN useradd sail` before export – Akshay Hegde May 27 '21 at 17:05
  • 1
    You can add `run mkdir -p /home/sail/` before `run echo ...` to make it existed. Also I recommend you change the `run echo ...` command to `RUN echo "export PATH='$PATH:$HOME/usr/local/bin/sqlpackage'" >> /home/sail/.bashrc`, but in this case `$HOME` means `/root/` am I right? – Saeed May 27 '21 at 17:09
  • `$HOME` is not required in echo export – Akshay Hegde May 27 '21 at 17:12
  • 1
    Ah snap, missed that. User sail gets created later. Your comments made me realize that. – Matt May 27 '21 at 17:35
  • @Matt i just added answer, hope this helps good day – Akshay Hegde May 27 '21 at 17:51

1 Answers1

1

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

Akshay Hegde
  • 16,536
  • 2
  • 22
  • 36