@@ -60,12 +60,25 @@ RUN if [ ${INSTALL_MONGO} = true ]; then \
6060 echo "extension=mongodb.so" >> /etc/php/7.0/cli/php.ini \
6161;fi
6262
63+ # ####################################
64+ # Non-Root User:
65+ # ####################################
66+
67+ # Add a non-root user to prevent files being created with root permissions on host machine.
68+ ARG PUID=1000
69+ ARG PGID=1000
70+ RUN groupadd -g $PGID laradock && \
71+ useradd -u $PUID -g laradock -m laradock
72+
73+ # Now switch to our laradock user for the rest of user setup
74+ USER laradock
75+
6376# ####################################
6477# Composer:
6578# ####################################
6679
6780# Add the composer.json
68- ADD ./composer.json /root /.composer/composer.json
81+ ADD ./composer.json /home/laradock /.composer/composer.json
6982
7083# Check if global install need to be runned
7184ARG COMPOSER_GLOBAL_INSTALL=true
@@ -84,13 +97,13 @@ ARG INSTALL_NODE=true
8497ENV INSTALL_NODE ${INSTALL_NODE}
8598RUN if [ ${INSTALL_NODE} = true ]; then \
8699 # Install nvm (A Node Version Manager)
87- curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.1 /install.sh | bash \
100+ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.3 /install.sh | bash \
88101;fi
89102# Again check if NVM needs to be installed
90- # I had to split this condifiton link this because when I get it inside the above if statment is refuses to work!
103+ # I had to split this condition link this because when I get it inside the above if statement is refuses to work!
91104ENV if [ ${INSTALL_NODE} = true ]; then \
92105 # Set the ENV
93- NVM_DIR=/root /.nvm \
106+ NVM_DIR=/home/laradock /.nvm \
94107 # Install NodeJS with NVM
95108 RUN . ~/.nvm/nvm.sh && \
96109 nvm install stable && \
@@ -99,13 +112,22 @@ ENV if [ ${INSTALL_NODE} = true ]; then \
99112 npm install -g gulp bower \
100113;fi
101114
115+ # Wouldn't execute when added to the RUN statement in the above block
116+ # Source NVM when loading bash since ~/.profile isn't loaded on non-login shell
117+ RUN if [ ${INSTALL_NODE} = true ]; then \
118+ echo "" >> ~/.bashrc && \
119+ echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc && \
120+ echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> ~/.bashrc \
121+ ;fi
122+
102123#
103124# --------------------------------------------------------------------------
104125# Final Touch
105126# --------------------------------------------------------------------------
106127#
107128
108129# Clean up
130+ USER root
109131RUN apt-get clean && \
110132 rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
111133
0 commit comments