From 17e252a4366bff3c8be0c08af86523dcf4ac5fdc Mon Sep 17 00:00:00 2001 From: Eric Pfeiffer Date: Wed, 27 Jul 2016 02:43:38 -0500 Subject: [PATCH 1/3] add non-root user for workspace container. --- docker-compose.yml | 4 +++- workspace/Dockerfile | 30 ++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index ab3dc0f..9d4f556 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,8 +10,10 @@ services: args: - INSTALL_MONGO=false - INSTALL_XDEBUG=false - - INSTALL_NODE=false + - INSTALL_NODE=true - COMPOSER_GLOBAL_INSTALL=false + - PUID=1000 + - PGID=1000 volumes_from: - volumes_source tty: true diff --git a/workspace/Dockerfile b/workspace/Dockerfile index db96f48..aac9bd6 100644 --- a/workspace/Dockerfile +++ b/workspace/Dockerfile @@ -60,12 +60,25 @@ RUN if [ ${INSTALL_MONGO} = true ]; then \ echo "extension=mongodb.so" >> /etc/php/7.0/cli/php.ini \ ;fi +##################################### +# Non-Root User: +##################################### + +# Add a non-root user to prevent files being created with root permissions on host machine. +ARG PUID=1000 +ARG PGID=1000 +RUN groupadd -g $PGID laradock && \ + useradd -u $PUID -g laradock -m laradock + +# Now switch to our laradock user for the rest of user setup +USER laradock + ##################################### # Composer: ##################################### # Add the composer.json -ADD ./composer.json /root/.composer/composer.json +ADD ./composer.json /home/laradock/.composer/composer.json # Check if global install need to be runned ARG COMPOSER_GLOBAL_INSTALL=true @@ -84,13 +97,13 @@ ARG INSTALL_NODE=true ENV INSTALL_NODE ${INSTALL_NODE} RUN if [ ${INSTALL_NODE} = true ]; then \ # Install nvm (A Node Version Manager) - curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash \ + curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.3/install.sh | bash \ ;fi # Again check if NVM needs to be installed -# I had to split this condifiton link this because when I get it inside the above if statment is refuses to work! +# I had to split this condition link this because when I get it inside the above if statement is refuses to work! ENV if [ ${INSTALL_NODE} = true ]; then \ # Set the ENV - NVM_DIR=/root/.nvm \ + NVM_DIR=/home/laradock/.nvm \ # Install NodeJS with NVM RUN . ~/.nvm/nvm.sh && \ nvm install stable && \ @@ -99,6 +112,14 @@ ENV if [ ${INSTALL_NODE} = true ]; then \ npm install -g gulp bower \ ;fi +# Wouldn't execute when added to the RUN statement in the above block +# Source NVM when loading bash since ~/.profile isn't loaded on non-login shell +RUN if [ ${INSTALL_NODE} = true ]; then \ + echo "" >> ~/.bashrc && \ + echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc && \ + echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> ~/.bashrc \ +;fi + # #-------------------------------------------------------------------------- # Final Touch @@ -106,6 +127,7 @@ ENV if [ ${INSTALL_NODE} = true ]; then \ # # Clean up +USER root RUN apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* From dd9855d4116c2fc6c3c404ef246a975ab1a445a5 Mon Sep 17 00:00:00 2001 From: Eric Pfeiffer Date: Wed, 27 Jul 2016 02:49:43 -0500 Subject: [PATCH 2/3] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 83c8388..f8cad06 100644 --- a/README.md +++ b/README.md @@ -227,6 +227,8 @@ You can select your own combination of container form this list: docker exec -it {Workspace-Container-Name} bash ``` Replace `{Workspace-Container-Name}` with your Workspace container name. +
+Add `--user=laradock` to have files created as your host's user. (don't forget to change the PUID (User id) and PGID (group id) variables in docker-compose.yml).
To find the containers names type `docker-compose ps`. @@ -657,7 +659,7 @@ More details about this [here](https://github.com/jenssegers/laravel-mongodb#ins 7 - Test it: - First let your Models extend from the Mongo Eloquent Model. Check the [documentation](https://github.com/jenssegers/laravel-mongodb#eloquent). -- Enter the Workspace Container `docker exec -it laradock_workspace_1 bash`. +- Enter the Workspace Container `docker exec -it --user=laradock laradock_workspace_1 bash`. - Migrate the Database `php artisan migrate`. From 20adc9ca1360370354413bbb21378d8d6c8b4030 Mon Sep 17 00:00:00 2001 From: Eric Pfeiffer Date: Wed, 27 Jul 2016 02:56:48 -0500 Subject: [PATCH 3/3] accidentally forgot to set INSTALL_NODE back to false. --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9d4f556..27e7e8b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: args: - INSTALL_MONGO=false - INSTALL_XDEBUG=false - - INSTALL_NODE=true + - INSTALL_NODE=false - COMPOSER_GLOBAL_INSTALL=false - PUID=1000 - PGID=1000