Docker-compose syntax - docker

RUN if [ "$NODE_ENV" = "development" ]; \
then npm install; \
else npm install --only=production: \
fi
When I try to run this code, I get that error message:
How can I fix that error?
=> ERROR [4/5] RUN if [ "development" = "development" ]; then npm install; else npm install --only=production: fi
0.3s
------
> [4/5] RUN if [ "development" = "development" ]; then npm install; else npm install --only=production: fi:
#8 0.291 /bin/sh: 1: Syntax error: end of file unexpected (expecting "fi")
------ executor failed running [/bin/sh -c if [ "$NODE_ENV" = "development" ]; then npm install; else npm install
--only=production: fi]: exit code: 2 ERROR: Service 'node-app' failed to build : Build failed

On the else line, there's a colon after --only=production, but I think you meant to use a semicolon instead:
RUN if [ "$NODE_ENV" = "development" ]; \
then npm install; \
else npm install --only=production; \
fi

Related

Could not open '/lib64/ld-linux-x86-64.so.2' on running npm install

I have a docker file I have built that uses the arm64v8/ arch type (I use an M1 Mac), no issues during the build at all, but as soon as try and install any npm dependencies I am met with this output:
root#456d8199a91d:/var/www/html# npm install
npm ERR! code 1
npm ERR! path /var/www/html/node_modules/optipng-bin
npm ERR! command failed
npm ERR! command sh -c node lib/install.js
npm ERR! compiling from source
npm ERR! Command failed: /var/www/html/node_modules/optipng-bin/vendor/optipng --version
npm ERR! qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
npm ERR!
npm ERR!
npm ERR! optipng pre-build test failed
npm ERR! Error: Command failed: /bin/sh -c make install
npm ERR! pngrtran.c:99:1: warning: 'png_rtran_ok' defined but not used [-Wunused-function]
npm ERR! 99 | png_rtran_ok(png_structrp png_ptr, int need_IHDR)
npm ERR! | ^~~~~~~~~~~~
npm ERR! ar: `u' modifier ignored since `D' is the default (see `U')
npm ERR! ar: `u' modifier ignored since `D' is the default (see `U')
npm ERR! ar: `u' modifier ignored since `D' is the default (see `U')
npm ERR! ar: `u' modifier ignored since `D' is the default (see `U')
npm ERR! pngxmem.c: In function 'pngx_malloc_rows_extended':
npm ERR! pngxmem.c:38:34: warning: comparison is always false due to limited range of data type [-Wtype-limits]
npm ERR! 38 | (pngx_alloc_size_t)height > (pngx_alloc_size_t)(-1) / sizeof(png_bytep))
npm ERR! | ^
npm ERR! ar: `u' modifier ignored since `D' is the default (see `U')
npm ERR! /usr/bin/ld: ../libpng/libpng.a(pngrutil.o): in function `png_read_filter_row':
npm ERR! pngrutil.c:(.text+0x1f64): undefined reference to `png_init_filter_functions_neon'
npm ERR! collect2: error: ld returned 1 exit status
npm ERR! make[1]: *** [Makefile:100: optipng] Error 1
npm ERR! make: *** [Makefile:14: install] Error 2
I notice that it mentions '/lib64/ld-linux-x86-64.so.2' which I only saw previously when trying to use the amd64 arch type for the same image build. My Dockerfile config is as follows:
FROM arm64v8/php:8.1-apache
RUN apt-get update
EXPOSE 80
RUN apt-get install -y \
git \
zip \
curl \
sudo \
unzip \
libicu-dev \
libbz2-dev \
libpng-dev \
libjpeg-dev \
libmcrypt-dev \
libreadline-dev \
libfreetype6-dev \
libonig-dev \
libzip-dev \
nodejs \
npm \
g++
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
RUN a2enmod rewrite headers
RUN docker-php-ext-install \
bz2 \
intl \
iconv \
bcmath \
opcache \
calendar \
mbstring \
pdo_mysql \
zip
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/
RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions pdo_pgsql
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# This needs to be set in .env as 'UID', must match the host id, attained using 'id -u'
# prevents root ownership on apache + other saved files
ARG uid
RUN useradd -G www-data,root -u $uid -d /home/devuser devuser
RUN mkdir -p /home/devuser/.composer && \
chown -R devuser:devuser /home/devuser
# Necessary drivers for redis adapter
RUN pecl channel-update pecl.php.net
RUN pecl install -f redis
RUN sudo apt update
RUN yes | apt install vim
Im not sure why it errors with what looks to be the wrong arch type being used when I have specified FROM arm64v8/php:8.1-apache? Bare in mind I have used this config for a couple of months with no issues until today, is there something blindingly obvious I'm missing in the npm install output?
Many thanks to #CharlesDuffy , as mentioned the version of optipng-bin I was attempting to install (2.0.0) was shipped with x86_64 libraries and nothing to support arm, bumping to 4.2.0 did the trick.

dockerfile npm install Permission denied

I have a "legacy" code (symfony) running on php7.3 and they were using node v6 and gulp for assets.
I want to build a Docker development environment, but I am having problems with node and permissions.
In my company, we use LDAP for authentication, so our user id is not 1000, so I need to create a user inside docker with the same host id and gid.
I have it almost working but when I try to install gulp I get this error:
Step 37/47 : RUN npm install -g gulp
---> Running in 607492f81dfe
npm WARN deprecated chokidar#2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
npm WARN deprecated source-map-resolve#0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated source-map-url#0.4.1: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated resolve-url#0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated urix#0.1.0: Please see https://github.com/lydell/urix#deprecated
/root/.nvm/versions/node/v6.17.1/bin/gulp -> /root/.nvm/versions/node/v6.17.1/lib/node_modules/gulp/bin/gulp.js
> es5-ext#0.10.59 postinstall /root/.nvm/versions/node/v6.17.1/lib/node_modules/gulp/node_modules/es5-ext
> node -e "try{require('./_postinstall')}catch(e){}"
sh: 1: node: Permission denied
/root/.nvm/versions/node/v6.17.1/lib
`-- (empty)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#^1.2.7 (node_modules/gulp/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! Linux 5.13.0-30-generic
npm ERR! argv "/root/.nvm/versions/node/v6.17.1/bin/node" "/root/.nvm/versions/node/v6.17.1/bin/npm" "install" "-g" "gulp"
npm ERR! node v6.17.1
npm ERR! npm v3.10.10
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! es5-ext#0.10.59 postinstall: `node -e "try{require('./_postinstall')}catch(e){}"`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the es5-ext#0.10.59 postinstall script 'node -e "try{require('./_postinstall')}catch(e){}"'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the es5-ext package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node -e "try{require('./_postinstall')}catch(e){}"
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs es5-ext
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls es5-ext
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /usr/src/app/npm-debug.log
npm ERR! code 1
Removing intermediate container 607492f81dfe
The command '/bin/sh -c npm install -g gulp' returned a non-zero code: 1
ERROR: Service 'app' failed to build : Build failed
This is the Dockefile I'm using:
FROM php:7.3-fpm
ARG USER_ID=1000
ARG GROUP_ID=1000
ARG DOCKER_TIMEZONE=${DOCKER_TIMEZONE}
ARG DEBUGMODE=0
ARG FOSJSDUMP=0
ARG TIMEZONE
ENV PS1="\u#\h:\w\\$ "
RUN echo "${DOCKER_TIMEZONE}" > /etc/timezone
RUN useradd -l -u ${USER_ID} -g users appuser
RUN groupmod --gid $GROUP_ID www-data
# 2 Set working directory
WORKDIR /usr/src/app
ENV NODE_VERSION=6.17.1
RUN apt install -y curl
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN node --version
RUN npm --version
RUN apt-get update && apt-get install -y \
gnupg \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip \
g++ \
procps \
openssl \
git \
unzip \
zlib1g-dev \
libzip-dev \
libfreetype6-dev \
libpng-dev \
libjpeg-dev \
libicu-dev \
libonig-dev \
libxslt1-dev \
acl \
&& echo 'alias sf="php bin/console"' >> ~/.bashrc
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install -j$(nproc) \
zip \
exif \
bcmath \
intl \
pcntl \
mysqli \
pdo \
gd \
pdo_mysql \
mbstring \
soap \
opcache \
iconv
# Install Imagick
RUN apt-get update && apt-get install -y \
libmagickwand-dev --no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-enable imagick
# xdebug extensions
RUN if [[ "$DEBUGMODE" = "0" ]] ; \
then \
echo "DEBUG MODE NOT ENABLED"; \
else \
# echo DEGUGMODE $DEBUGMODE \
pecl install xdebug && docker-php-ext-enable xdebug \
; fi
#
# ldap
RUN apt-get install libldap2-dev -y && \
rm -rf /var/lib/apt/lists/* && \
docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \
docker-php-ext-install ldap
# Redis
RUN pecl install -o -f redis && rm -rf /tmp/pear && docker-php-ext-enable redis
# Set timezone
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone \
&& printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini \
&& "date"
# Install Composer
RUN echo "Install Composer"
RUN composer --version
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
WORKDIR /usr/src/app
RUN npm install -g gulp
RUN gulp prod
# 8 Copy existing application directory permissions
COPY --chown=appuser:appuser . /usr/src/app
RUN composer install --no-scripts --prefer-dist --no-interaction --optimize-autoloader
RUN php bin/console cache:clear
RUN mkdir -p /usr/src/app/web/uploads
RUN chmod -R 777 /usr/src/app/web/uploads
#RUN chown -R www-data:www-data /usr/src/app
# 9 Change current user
USER appuser
# 10 Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm", "-F"]
WORKDIR /usr/src/app
Any help or clue?

Why does yarn fail on a Docker in Mac, but is successful in linux?

I have a simple Dockerfile which works perfectly on linux but fails on Mac exclusively.
the step that fails is
RUN source /root/.bashrc && \
yarn && \
yarn build && \
yarn global add serve
The complete Dockefile is (edited)
FROM alpine:latest
WORKDIR /root
RUN apk update && \
apk upgrade && \
apk add git g++ gcc libgcc libstdc++ linux-headers make python2 aws-cli jq && \
apk update
#-- Download and compile specific nodejs version required (10.16.3)
RUN wget https://nodejs.org/dist/v10.16.3/node-v10.16.3.tar.gz
RUN tar -xvzf node-v10.16.3.tar.gz
WORKDIR /root/node-v10.16.3/
RUN ./configure
RUN make -j4
RUN make install
RUN ln -s /usr/local/bin/node /usr/bin/node
RUN rm -rf /root/node-v10.16.3*
#-- Download and install spcific verion for yarn (1.17.3)
WORKDIR /opt
RUN wget https://github.com/yarnpkg/yarn/releases/download/v1.17.3/yarn-v1.17.3.tar.gz
RUN tar -xvzf yarn-v1.17.3.tar.gz
RUN echo export PATH="$PATH:/opt/yarn-v1.17.3/bin" > /root/.bashrc
RUN source /root/.bashrc
#-- install libsass
WORKDIR /opt
RUN git clone https://github.com/sass/sassc && cd sassc && \
git clone https://github.com/sass/libsass && \
SASS_LIBSASS_PATH=/opt/sassc/libsass make && \
mv bin/sassc /usr/bin/sassc && \
cd ../ && rm -rf /sassc
# created node-sass binary
ENV SASS_BINARY_PATH=/usr/lib/node_modules/node-sass/build/Release/binding.node
RUN git clone --recursive https://github.com/sass/node-sass.git && \
cd node-sass && \
git submodule update --init --recursive && \
npm install && \
node scripts/build -f && \
cd ../ && rm -rf node-sass
# add binary path of node-sass to .npmrc
RUN touch $HOME/.npmrc && echo "sass_binary_cache=${SASS_BINARY_PATH}" >> $HOME/.npmrc
ENV SKIP_SASS_BINARY_DOWNLOAD_FOR_CI true
ENV SKIP_NODE_SASS_TESTS true
RUN apk add aws-cli jq bash
#--
ARG ENV=prod
EXPOSE 80
RUN mkdir -p /opt/something
RUN whoami
WORKDIR /opt/something
COPY . /opt/something/
RUN chmod +x /opt/something/start_container.sh
RUN cat /root/.bashrc
RUN cp .env .env.production
RUN source /root/.bashrc && \
yarn && \
yarn build && \
yarn global add serve
ENTRYPOINT [ "/opt/something/start_container.sh" ]
When it fails on Mac i get
Step 17/18 : RUN source /root/.bashrc && yarn && yarn build && yarn global add serve
---> Running in ddb97ab31a65
yarn install v1.17.3
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents#2.1.2: The platform "linux" is incompatible with this module.
info "fsevents#2.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents#1.2.11: The platform "linux" is incompatible with this module.
info "fsevents#1.2.11" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "#amcharts/amcharts4 > canvg#2.0.0" has unmet peer dependency "canvas#^2.1.0".
warning "#amcharts/amcharts4 > canvg#2.0.0" has unmet peer dependency "jsdom#^13.0.0".
warning "#amcharts/amcharts4 > canvg#2.0.0" has unmet peer dependency "xmldom#^0.1.27".
warning "react-final-form > ts-essentials#5.0.0" has incorrect peer dependency "typescript#>=3.7.0".
warning "react-scripts > eslint-config-react-app#5.2.0" has incorrect peer dependency "eslint-plugin-flowtype#3.x".
[4/4] Building fresh packages...
Done in 63.56s.
yarn run v1.17.3
$ react-scripts build
Creating an optimized production build...
Browserslist: caniuse-lite is outdated. Please run the following command: `yarn upgrade`
Failed to compile.
Failed to minify the bundle. Error: static/js/3.9a1e52a6.chunk.js from Terser
Error: Call retries were exceeded
at compiler.run (/opt/something/node_modules/react-scripts/scripts/build.js:196:23)
at finalCallback (/opt/something/node_modules/webpack/lib/Compiler.js:257:39)
at hooks.done.callAsync.err (/opt/something/node_modules/webpack/lib/Compiler.js:273:13)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/opt/something/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (/opt/something/node_modules/tapable/lib/Hook.js:154:20)
at onCompiled (/opt/something/node_modules/webpack/lib/Compiler.js:271:21)
at hooks.afterCompile.callAsync.err (/opt/something/node_modules/webpack/lib/Compiler.js:681:15)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/opt/something/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (/opt/something/node_modules/tapable/lib/Hook.js:154:20)
at compilation.seal.err (/opt/something/node_modules/webpack/lib/Compiler.js:678:31)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/opt/something/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (/opt/something/node_modules/tapable/lib/Hook.js:154:20)
at hooks.optimizeAssets.callAsync.err (/opt/something/node_modules/webpack/lib/Compilation.js:1423:35)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/opt/something/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (/opt/something/node_modules/tapable/lib/Hook.js:154:20)
at hooks.optimizeChunkAssets.callAsync.err (/opt/something/node_modules/webpack/lib/Compilation.js:1414:32)
(there are no connection problems with the repo it is trying to get from)
I'm really stomped by this. I'm just building on linux and that's fine, but i can't build on my local mac for dev...
Any pointers would be appreciated!
EDIT: I use the EXACT same base image on both linux and Mac, but it only fails in Mac... it's really weird.
David

Conditional npm install ARG in Dockerfile

I am trying to install node module packages from GitHub on the basis of the argument. I have tried but however I do not understand this solution completely. There is no error in the execution but I am sure it does not install the package. I run the container locally before deploy and getting the module not found an error
Dokerfile is like that.Can it be possible to keep each command in a new line?
FROM node:10
ENV HOME /usr/src/reach-live-api
ARG siteval
RUN mkdir -p $HOME
RUN mkdir -p /root/.ssh
WORKDIR $HOME
COPY ./keys/reachlive_rsa /root/.ssh/id_rsa
RUN chmod 700 /root/.ssh/id_rsa
RUN echo "Host bitbucket.org\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config
COPY . $HOME
RUN npm install --silent --production
RUN if [ "$siteval" = "prod" ]; then \
RUN npm install "reach-live-elasticsearch#git+https://github.com/lalitmohan001/reach-live-elasticsearch-prod.git" \
RUN npm install "reach-live-firebase#git+https://github.com/lalitmohan001/reach-live-firebase-prod.git" \
RUN npm install "reach-live-paypal#git+https://github.com/lalitmohan001/reach-live-paypal-prod.git" \
else \
RUN npm install "reach-live-elasticsearch#git+https://github.com/lalitmohan001/reach-live-elasticsearch.git" \
RUN npm install "reach-live-firebase#git+https://github.com/lalitmohan001/reach-live-firebase.git" \
RUN npm install "reach-live-paypal#git+https://github.com/lalitmohan001/reach-live-paypal.git"; \
fi
RUN npm prune --production
RUN rm -fr .npm
RUN rm -fr /root/.ssh
RUN rm -fr keys
CMD ["npm", "start"]
I use the following command to build
docker build -t gcr.io/reachlive-123/api:25Apr2020 . --build-arg siteval=dev
Help would be much appreciated
turns out the problem was in the
RUN if [ "$siteval" = "prod" ]; then \
RUN npm install "reach-live-elasticsearch#git+https://github.com/lalitmohan001/reach-live-elasticsearch-prod.git" \
RUN npm install "reach-live-firebase#git+https://github.com/lalitmohan001/reach-live-firebase-prod.git" \
RUN npm install "reach-live-paypal#git+https://github.com/lalitmohan001/reach-live-paypal-prod.git" \
else \
RUN npm install "reach-live-elasticsearch#git+https://github.com/lalitmohan001/reach-live-elasticsearch.git" \
RUN npm install "reach-live-firebase#git+https://github.com/lalitmohan001/reach-live-firebase.git" \
RUN npm install "reach-live-paypal#git+https://github.com/lalitmohan001/reach-live-paypal.git"; \
fi
I have changed it to and it works
RUN if [ "$arg" = "prod" ]; then \
npm install reach-live-elasticsearch#git+https://github.com/lalitmohan001/reach-live-elasticsearch-prod.git \
reach-live-firebase#git+https://github.com/lalitmohan001/reach-live-firebase-prod.git \
reach-live-paypal#git+https://github.com/lalitmohan001/reach-live-paypal-prod.git ; \
else \
npm install reach-live-elasticsearch#git+https://github.com/lalitmohan001/reach-live-elasticsearch.git \
reach-live-firebase#git+https://github.com/lalitmohan001/reach-live-firebase.git \
reach-live-paypal#git+https://github.com/lalitmohan001/reach-live-paypal.git; \
fi
Thanks to Pavittar Singh for helping us figure this out!

Docker exec npm command

I have successfully build docker container with node in it.
When I ssh'd into it, npm, node commands works as expected, but when I'm trying to execute command remotely (docker exec vvs_workspace npm install), it prints rpc error: code = 2 desc = oci runtime error: exec failed: exec: "npm": executable file not found in $PATH
Dockerfile:
#####################################
# Node / NVM:
#####################################
ENV NVM_DIR=/home/dockuser/.nvm
ENV NODE_VERSION 6.3.1
RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.31.3/install.sh | bash \
&& . ~/.nvm/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/v$NODE_VERSION/bin:$PATH
RUN echo "" >> ~/.bashrc && \
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc && \
echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> ~/.bashrc
P.S. when executing docker exec vvs_workspace composer install everything is ok.
I found the solution, https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/issues/82 , just add ENV PATH $PATH:/home/laradock/.nvm/versions/node/v6.8.0/bin in your Dockfile. change /home/laradock/.nvm/versions/node/v6.8.0/bin to your nvm path.

Resources