0

I have problem if I add script start cron service in ubuntu image then my container booted up for a few seconds then exited, I see log with path docker logs api-nodejs it show only result * Starting periodic command scheduler cron [ OK ] In my ubuntu image has install crontab following content

FROM ubuntu:16.04

RUN apt-get update \
   && apt-get install -y curl \
   && apt-get install -y vim \
   && apt-get install -y cron

USER root

# set timezone
ENV TZ 'Asia/Ho_Chi_Minh'
RUN echo $TZ > /etc/timezone && \
    apt-get update && apt-get install -y tzdata && \
    rm /etc/localtime && \
    ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
    dpkg-reconfigure -f noninteractive tzdata && \
    apt-get clean

# install node version 13.*
RUN curl -sL https://deb.nodesource.com/setup_13.x | bash - \
    && apt-get install -y nodejs 
RUN npm install -g nodemon
# result installation
RUN node -v
RUN npm -v
RUN nodemon -v

WORKDIR /var/www/html/backend/

EXPOSE 4000
EXPOSE 5000

docker-compose.yml with content

version: "3.3"
services:
  app-backend:
    container_name: api-nodejs
    image: ubuntu:16.04
    stdin_open: true
    tty: true
    build: ./app/backend
    volumes:
      - ./src/console-be:/var/www/html/backend/
    ports:
      - "4000:4000"
      - "5000:5000"
    command: npm run debug
    entrypoint: ["/etc/init.d/cron", "start"]

I want to run multiple cmd (start cron service and my api nodejs app) while run docker container.

Is there any solution for me in this case? Thanks!

Levi
  • 59
  • 4
  • You have two problems here : "running multiple commands from a Dockerfile", AND understanding the difference between command and entrypoint. The 2 of them are very common questions, and you will find a large amount of answers googling thoses questions or searching within SOO – Marvin Mar 31 '22 at 07:23
  • Init scripts broadly don't work in Docker. A container runs _one_ process and it must run in the foreground. It's fine to run multiple containers off the same image with different commands. The linked question has several recipes to run a cron daemon as a foreground process in its own container. – David Maze Mar 31 '22 at 11:03

0 Answers0