0

I need to start script in busybox container which will outuput the date and words the busybox is running when I'm up my compose file i just see that:

busybox_1 | tail: invalid number 'sh ./5sec.sh'

This is my script:

while true; do
sleep 5
date
echo busybox is running
done

It's my Dockerfile:

  FROM busybox:noauto
    COPY /5sec.sh /5sec.sh
    RUN chmod 777 5sec.sh
    CMD ./5sec.sh

It's my compose file (just in case) :

version: '3'
services:
nginx:
image: "nginx:latest"
env_file: .env
ports:
- $HTTP_PORT:80
volumes:
- nginx-vol:/var/log/nginx
busybox:
image: "busybox:noauto"
volumes:
- nginx-vol:/var/log/nginx
volumes:
nginx-vol:
 

Help me please. How to start script automaticly. (Sorry for bad English)

  • I'm not sure where that error is coming from, because you don't seem to be calling `tail` anywhere here. – larsks Feb 04 '21 at 23:29
  • If at some point you had both `build:` and `image:`, and the `image:` was the same as your Dockerfile `FROM` line, your later rebuilds would just be adding content on top of the previous image. That could be one source of confusion. – David Maze Feb 05 '21 at 00:23

1 Answers1

0

I don't know what is this docker image busybox:noauto (probably your local image - build by you), and I guess this is reason of your problem. It's look like this image have some RUN command with tail or something like it.

I propose to use some standard busybox from dockerhub for your base image, for example busybox:1:

 FROM busybox:1
    COPY /5sec.sh /5sec.sh
    RUN chmod 777 5sec.sh
    CMD ./5sec.sh

Second question you should use build instead of image in you docker-compose.yaml if you want build image by yourself from your Dockerfile:

version: '3'
services:
  nginx:
    image: "nginx:latest"
    env_file: .env
    ports:
      - $HTTP_PORT:80
    volumes:
      - ./nginx-vol:/var/log/nginx
  busybox:
    build: .
    volumes:
      - ./nginx-vol:/var/log/nginx

This should solve your problem.

Notes:

  • chmod 777 isn't a good practice
  • script should start with Shebang - #!/bin/sh in your case
velmafia
  • 26
  • 5