Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
283 views
in Technique[技术] by (71.8m points)

docker - BUSYBOX script is wrong

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)

question from:https://stackoverflow.com/questions/66055072/busybox-script-is-wrong

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...