When trying to run a container built from this dockerfile, I keep getting an error /home/web/frontendstart.sh: line 25: ng: command not found and then a segmentation fault when it reaches the final line in frontendstart.sh,ng serve --port 8081 --host 0.0.0.0 .
Docker Version: 4.19.0 Mac OS: 14.3 Processor: Intel
Dockerfile
# Base image ubuntu cause its easy
FROM ubuntu:latest AS base
LABEL project="LimbRescue"
LABEL release="DEV"
# Configure Routes
# TODO see if we can remove (this should not be necessary with docker-compose)
EXPOSE 8443/tcp
# Get needed software from apt,
# remove apt lists to save space
RUN apt-get update \
&& apt-get -y install \
git \
mysql-server \
maven \
nginx \
curl \
&& rm -rf /var/lib/apt/lists/*
RUN useradd -ms /bin/bash web
USER web
# Installs the long term support version of nodejs,
# NOTE: this may be newer than apt-get nodejs as found out on 6/10/22
# I understand that "curl <url> | bash" is bad practice. This seems to be the only way
# to get nvm, and nvm is way we have to manage node version since apt-get can have
# very old versions of nodejs. If a better way becomes avalible then please use it.
# Weird shell commands because nvm wants to use ~/.bashrc solution found below:
# https://stackoverflow.com/questions/25899912/how-to-install-nvm-in-docker/60137919#60137919
SHELL ["/bin/bash", "--login", "-i", "-c"]
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
ENV NODE_OPTIONS="--max_old_space_size=4096 --openssl-legacy-provider"
RUN source /home/web/.bashrc \
&& nvm install --lts
SHELL ["/bin/bash", "--login", "-c"]
FROM base AS setup
# Sets up the sql server
USER root
WORKDIR /root
COPY src/* .
COPY src/dev/* .
COPY data/* .
RUN /bin/bash setup.sh
RUN chmod +x /root/start.sh
# Starts the front/backend servers
FROM setup AS start
WORKDIR /home/web
#ENTRYPOINT /bin/bash;
ENTRYPOINT /root/start.sh; tail -f /dev/null
Start.sh
service mysql start
# try moving backend start
if test -f "/root/backendstart.sh"; then
mv /root/backendstart.sh /home/web/backendstart.sh
chown web:web /home/web/backendstart.sh
else
echo "/root/backendstart.sh not found, may have already been moved to /home/web"
fi
# try moving front end start
if test -f "/root/frontendstart.sh"; then
mv /root/frontendstart.sh /home/web/frontendstart.sh
chown web:web /home/web/frontendstart.sh
else
echo "/root/frontendstart.sh not found, may have already been moved to /home/web"
fi
# check for backend start
if test -f "/home/web/backendstart.sh"; then
su -c "/bin/bash /home/web/backendstart.sh &" web
else
echo "Could not find /home/web/backendstart.sh?? unable to continue"
fi
# Check for frontend start
if test -f "/home/web/frontendstart.sh"; then
su -c "/bin/bash /home/web/frontendstart.sh &" web
else
echo "Could not find /home/web/frontendstart.sh?? unable to continue"
fi
Frontendstart.sh
#!/bin/bash
# Stolen from .bashrc
# Makes npm work
export NVM_DIR="$HOME/.nvm"
# This loads nvm
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# This loads nvm bash_completion
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# Updates our code and starts the npm server
cd /home/web/LimbRescueAngularAppFrontend/LimbRescue
# Development specific globals
cp src/app/global/Constants-dev.ts src/app/global/Constants.ts
echo "Upgrading NPM"
npm upgrade
echo "Installing npm packages"
npm install
ng update
npm update
echo "Installing angular/cli "
npm install -g @angular/cli
npm install -g @angular-devkit/build-angular
echo "Running on port 8081"
ng serve --port 8081 --host 0.0.0.0
echo "Done"
My peers are able to build an image using this code and run the container successfully. Since all the dependencies of the project are installed through docker, and since I am using the exact same codebase, I suspected that the issue had something to do with my machine.
I've tried:
- Updating my mac to Sonoma 14.3
- Downgrading docker to 4.19.0
- Allocating additional RAM to Docker