Install node and npm on Docker

I have my application (Laravel) running in a Docker container.

I am now trying to use Laravel Mix to compile my assets. To do this I need node and npm, I am therefore trying to use a separate container to so this.

My Dockerfile just has this:
FROM node:8

my docker-compose:

mix:
build:
context: ./docker/mix
args:
- DOCKER_ENV=${DOCKER_ENV}
container_name: mix
volumes:
- ${PROJECT_PATH}/src:/srv/app
environment:
- DOCKER_ENV=${DOCKER_ENV}
- APP_DEBUG=${APP_DEBUG}

When I try to build I keep getting Exit Code 0 from this container.

I just want a container to build my assets on, am I doing the right thing.:

https://laravel.com/docs/5.6/mix#running-mix

Thanks,

Mick

So you are wanting to keep the container running so that you can exec into it and run commands such as npm run right?.

If that is the case, you just have to set the container to run a command that will stay open to keep the container from exiting. The reason the container is exiting is because you have not specified any command for the container to run when it is started. You should do something like this.

docker-compose.yml:

mix:
  build:
    context: ./docker/mix
    args:
      - DOCKER_ENV=${DOCKER_ENV}
  container_name: mix
  # The std_open and tty settings are to make sure that the `sh` command
  # waits for input instead of exiting.
  stdin_open: true
  tty: true
  command: sh # Start `sh` when the container starts to keep container from exiting.
  volumes:
    - ${PROJECT_PATH}/src:/srv/app
  environment:
    - DOCKER_ENV=${DOCKER_ENV}
    - APP_DEBUG=${APP_DEBUG}

Then you should be able to docker-compose exec mix bash and get a terminal to run whatever commands you want to inside the container.