0

I'm running a docker compose with a custom Dockerfile build. I tried ENTRYPOINT & CMD with a sleep 99999999999999999999, but the container immediately exited with code 0.

Here is the d.mi.docker-compose.yml

services:
  traefik:
    image: "traefik:v2.10"
    container_name: "traefik"
    command:
      #- "--log.level=DEBUG"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
    ports:
      - "127.0.0.1:80:80"
      - "127.0.0.1:8080:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
  mi-www_site:
    container_name: mi-www_site
    build:
      dockerfile: ./d.mi-www_site.Dockerfile
    env_file:
      - .env
    environment:
      USE_S3: 1
      REDIS_HOST: "mi-redis"
    expose:
      - "80"
      - "443"
      - "6379"
    ports:
      - 127.0.0.1:${MI_WWW_SITE_PORT}:${MI_WWW_SITE_PORT}
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.whoami.rule=Host(`mi-www.site`)"
      - "traefik.http.routers.whoami.entrypoints=web"
  redis:
    image: redis:alpine
    container_name: mi-redis
    read_only: false
    restart: unless-stopped
    env_file:
      - .env
    environment:
      REDIS_ARGS: --port 6379 --save 20 1 --loglevel warning
    ports:
      - "6379"
    volumes:
      - /var/lib/mi-redis:/var/lib/redis
      - ./apps/mi-www.site/etc/redis:/etc/redis

Here is d.mi-www_site.Dockerfile

FROM node:current-alpine
ARG USER
ARG UID=1000
ARG GID
WORKDIR /app
COPY apps/mi-www.site/dist ./
EXPOSE 4009
#CMD ["node", "./server/entry.mjs"]
ENTRYPOINT ["sleep", "99999999999999999999"]
#CMD ["sleep", "99999999999999999999"]

Here is the cli:

❯ docker compose -f d.mi.docker-compose.yml up
[+] Running 3/0
 ✔ Container traefik      Created                                                                                                                                                                                                                                                      0.0s
 ✔ Container mi-redis     Created                                                                                                                                                                                                                                                      0.0s
 ✔ Container mi-www_site  Created                                                                                                                                                                                                                                                      0.0s
Attaching to mi-redis, mi-www_site, traefik
mi-redis     | 1:C 14 Jul 2023 06:13:10.469 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
mi-redis     | 1:C 14 Jul 2023 06:13:10.469 # Redis version=7.0.12, bits=64, commit=00000000, modified=0, pid=1, just started
mi-redis     | 1:C 14 Jul 2023 06:13:10.469 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
mi-redis     | 1:M 14 Jul 2023 06:13:10.469 * monotonic clock: POSIX clock_gettime
mi-redis     | 1:M 14 Jul 2023 06:13:10.469 * Running mode=standalone, port=6379.
mi-redis     | 1:M 14 Jul 2023 06:13:10.469 # Server initialized
mi-redis     | 1:M 14 Jul 2023 06:13:10.470 * Loading RDB produced by version 7.0.12
mi-redis     | 1:M 14 Jul 2023 06:13:10.470 * RDB age 122 seconds
mi-redis     | 1:M 14 Jul 2023 06:13:10.470 * RDB memory usage when created 0.82 Mb
mi-redis     | 1:M 14 Jul 2023 06:13:10.470 * Done loading RDB, keys loaded: 0, keys expired: 0.
mi-redis     | 1:M 14 Jul 2023 06:13:10.470 * DB loaded from disk: 0.000 seconds
mi-redis     | 1:M 14 Jul 2023 06:13:10.470 * Ready to accept connections
traefik      | time="2023-07-14T06:13:10Z" level=info msg="Configuration loaded from flags."
mi-www_site exited with code 0

Why did the custom container immediately exited with code 0 & how do I keep it running?

Brian Takita
  • 1,615
  • 1
  • 15
  • 20
  • A container running `sleep` doesn't seem very useful. (Without Docker, would you ever run a very long `sleep` command so you could "have a process running"?) Would it make more sense to focus on one of the commented-out lines, like the `CMD` option that runs the Node application? – David Maze Jul 14 '23 at 10:13
  • It's the same behavior. I just wanted to isolate the problem to the Docker config. When I run CMD ./server/entry.mjs on the host OS, the web server runs. When used with docker compose, it immediately exited with code 0. – Brian Takita Jul 14 '23 at 13:37
  • 1
    Also see the comments on [Alpine 3.18 Docker image not respecting `sleep` shell command after a background command run with &](https://stackoverflow.com/questions/76687757/alpine-3-18-docker-image-not-respecting-sleep-shell-command-after-a-background), which are suggesting that on at least one specific version of BusyBox, sleep(1) doesn't actually sleep. – David Maze Jul 14 '23 at 13:39
  • Switching to node:current-alpine3.17 fixed the problem. Thank you! node ./server/entry.mjs does not stay open either so it seems like it could be a problem with running long-lived processes? – Brian Takita Jul 14 '23 at 14:04

0 Answers0