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)

2
  • I'm not sure where that error is coming from, because you don't seem to be calling tail anywhere here. Commented Feb 4, 2021 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. Commented Feb 5, 2021 at 0:23

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.