Run npm test inside a docker image and exit

7/13/2018

I have basically a docker image of a node js application.

REPOSITORY TAG IMAGE ID CREATED SIZE abc-test 0.1 1ba85e0ca455 7 hours ago 1.37GB

I want to run npm test from folder /data/node/src but that doesn't seems to be working.

Here is the command what I am trying:

docker run -p 80:80 --entrypoint="cd /data/node/src && npm run test" abc-test:0.1

But that doesn't seems to be working.

Here is my dockerfile:

FROM python:2.7.13-slim
RUN apt-get update && apt-get install -y apt-utils curl
RUN echo 'deb http://nginx.org/packages/debian/ jessie nginx' > /etc/apt/sources.list.d/nginx.list

RUN apt-get update && apt-get install -y \
    build-essential \
    gcc \
    git \
    libcurl4-openssl-dev \
    libldap-2.4-2 \
    libldap2-dev \
    libmysqlclient-dev \
    libpq-dev \
    libsasl2-dev \
    nano \
    nginx=1.8.* \
    nodejs \
    python-dev \
    supervisor

ENV SERVER_DIR /data/applicationui/current/server

ADD src/application/server $SERVER_DIR

EXPOSE 14000 80
# version A: only start tornado, without nginx.
 WORKDIR $SERVER_DIR/src
 CMD ["npm","run","start:staging"]

Can anyone please help me here.

-- kaounKaoun
docker
github
jenkins
kubernetes
node.js

1 Answer

7/13/2018

Pretty sure you can only run one command with ENTRYPOINT and with CMD.

From their docs:

There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.

Same thing with Entrypoint:

ENTRYPOINT has two forms:

  1. ENTRYPOINT ["executable", "param1", "param2"] (exec form, preferred)
  2. ENTRYPOINT command param1 param2 (shell form)

https://docs.docker.com/engine/reference/builder/#cmd https://docs.docker.com/engine/reference/builder/#entrypoint

A work around that I do is the following

FROM ubuntu:16.04
WORKDIR /home/coins
RUN apt-get update

...
OTHER DOCKERFILE STUFF HERE
...


COPY ./entrypoint.sh /home/coins/
RUN chmod +x ./entrypoint.sh
ENTRYPOINT ./entrypoint.sh

entrypoint.sh:

#!/bin/bash
Can write whatever sh commands you need here..
exec sh ./some_script

EDIT:

One idea is you can add a test sh script and just trigger those 2 commands in it, and you'd be able to launch it with --entrypoint="test.sh"

-- lrossy
Source: StackOverflow