jsabina
jsabina

Reputation: 198

run a script after docker-compose run (npm)

I am an absolute beginner on this.

I need to run two containers, with two separate apps. One of them should run a script (which runs npm start and not much else), but that might not be possible?

Dockerfile

FROM node:14.16.0-buster
RUN apt-get update && apt-get install -y libsecret-1-dev groff less bash-completion && rm -rf /var/lib/apt/lists/*
ENV npm_config_user root
COPY startscript.sh /usr/local/bin
RUN chmod +x /usr/local/bin/startscript.sh
ENTRYPOINT []

And the docker-compose.yml

version: '3'

services:
    first-container:
        build:
            context: .
        ports:
            - '8080:8080' # node web interface
        env_file: .env
        command: bash -c "/usr/local/bin/startscript.sh"

    second-container:
        build:
            context: .
        ports:
        - '8181:8181' # node main app web interface

       # volumes:

 volumes:
    node-modules: # persist local node_modules

I can run the containers, but the script doesn't run automatically. Suggestions?

thanks

Upvotes: 1

Views: 2977

Answers (1)

Mustafa Güler
Mustafa Güler

Reputation: 1014

Just run with ENTRYPOINT ["npm","start"]

And you want to run 2 commands just create a script file script.sh

#!/bin/bash

npm start &

# Other command here

Then ENTRYPOINT ["/script.sh"]

Upvotes: 1

Related Questions