0

Lets say we have three services - php+ apache - mysql - nodejs

I know how to use docker-compose to setup application to link mysql with php apache service. I was wondering how we can add node.js service just to manage js/css assets. The purpose of node.js service is to just manage javascript/css resources. Since docker provides this flexibility I was wondering to use docker service instead of setting up node.js on my host computer.

version: '3.2'

services:
  web:
    build: .
    image: lap
    volumes:
      - ./webroot:/var/www/app
      - ./configs/php.ini:/usr/local/etc/php/php.ini
      - ./configs/vhost.conf:/etc/apache2/sites-available/000-default.conf
    links:
      - dbs:mysql
  dbs:
    image: mysql
    ports:
      - "3307:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_PASSWORD=rest
      - MYSQL_DATABASE=symfony_rest
      - MYSQL_USER=restman
    volumes:
      - /var/mysql:/var/lib/mysql
      - ./configs/mysql.cnf:/etc/mysql/conf.d/mysql.cnf
  node:
    image: node
    volumes:
      - ./webroot:/var/app
    working_dir: /var/app

I am not sure this is correct strategy , I am sharing ./webroot with both web and node service. docker-compose up -d only starts mysql and web and fails to start node container , probably there is not valid entrypoint set.

sakhunzai
  • 13,900
  • 23
  • 98
  • 159
  • disregard my question this solved my issue https://stackoverflow.com/questions/36249744/interactive-shell-using-docker-compose – sakhunzai Feb 20 '18 at 14:02

2 Answers2

0

You can also add nginx service to docker-compose, and nginx can take care of forwarding requests to php container or node.js container. You need some server that binds to 80 port and redirect requests to designated container.

Akash Sharma
  • 721
  • 3
  • 6
  • 1
    I just need npm to add some node tools , I dont think port forwarding will do anything here, if you have a solution please share – sakhunzai Feb 21 '18 at 04:43
0

if you want to use node js separate from PHP service you must set two more options to make node stay up, one is stdin_open and the other one is tty like bellow

stdin_open: true
tty: true

this is equivalent to CLI command -it like bellow

docker container run --name nodeapp -it node:latest

if you have a separate port to run your node app (e.g. your frontend is completely separate from your backend and you must run it independently from your backend like you must run npm run start command in order to run the frontend app) you must publish your port like bellow

ports:
  - 3000:3000

ports structure is systemPort:containerInnerPort.

this means publish port 3000 from inside node container to port 3000 on the system, in another way your make port 3000 inside your container accessible on your system and you can access this port like localhost:3000.

in the end, your node service would be like bellow

node:
  image: node
  stdin_open: true
  tty: true
  volumes:
    - ./webroot:/var/app
  working_dir: /var/app
adnan ahmady
  • 770
  • 1
  • 7
  • 12