How to write a Docker file that I can start a service and start a shell, and also accept arguments for the shell?

In the Docker file, the last instruction:

CMD  sudo chown -R user:user /home/user/che && \
     sudo service docker start && \
     cd /home/user/che/bin/ && ./che.sh run

It works, but I can not pass more arguments ./che.sh.

che.shchecks if the internal one is dockerrunning after completing other tasks. And it may take several optional arguments, for example -r:111.111.111.111.

I tried changing the instruction as:

RUN sudo chown -R user:user /home/user/che && \
     sudo service docker start
ENTRYPOINT ["/home/user/che/bin/che.sh"]

to call it like docker run -it --priviledged my/che -r:111.111.111.111 run, but the shell che.shwill report that the internal dockeris not working properly.

I also tried:

ENTRYPOINT ["sudo service docker start", "&&", "/home/user/che/bin/che.sh run"]

even

ENTRYPOINT ["sh", "-c" "sudo service docker start && /home/user/che/bin/che.sh run"]

But it will report that it is sudo service docker startnot found in $ PATH, or che.shdoes not start.

What is the correct way to write it?

  • sudo service docker start should start when called che.sh
  • I need to pass arguments from outside to che.she.g.docker run -it --priviledged my/che -r:111.111.111.111 run
+4
2

supervisord Docker, .

: https://docs.docker.com/engine/articles/using_supervisord/

( ) $ docker run, systemd (- systemd) docker-compose. yml Dockerfiles.

supervisord Docker:

RUN apt-get -y update && apt-get -y dist-upgrade \
    && apt-get -y install \
        supervisor
RUN mkdir -p /var/log/supervisord

Docker:

COPY etc/supervisor/conf.d/supervisord.conf /etc/supervisor/conf.d/
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]

etc/supervisor/conf.d/supervisord.conf Docker:

[unix_http_server]
file=/var/run/supervisord.sock
chmod=0777
chown=root:root
username=root

[supervisord]
nodaemon=true
user=root
environment=HOME="/root",USER="root"
logfile=/var/log/supervisord/supervisord.log
pidfile=/var/run/supervisord.pid
childlogdir=/var/log/supervisord
logfile_maxbytes=10MB
loglevel=info

[program:keepalive]
command=/bin/bash -c 'echo Keep Alive service started... && tail -f /dev/null'
autostart=true
autorestart=true
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile=/var/log/supervisord/keepalive-stdout.log
stdout_logfile_maxbytes=1MB
stderr_logfile=/var/log/supervisord/keepalive-stderr.log
stderr_logfile_maxbytes=1MB

[program:dcheck]
command=/bin/bash -c 'chmod +x /root/dcheck/repo/dcheck.sh && cd /root/dcheck/repo && ./dcheck.sh'
autostart=true
autorestart=true
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile=/var/log/supervisord/dcheck-stdout.log
stdout_logfile_maxbytes=10MB
stderr_logfile=/var/log/supervisord/dcheck-stderr.log
stderr_logfile_maxbytes=1MB

supervisord.conf , , , . , bash script.

docker exec , :

docker exec -it your_running_container /bin/bash -c 'tail -f /var/log/supervisord/dcheck-stdout.log'

loglevel=debug, , bash , script.

, tail -f /dev/null, ..sh script .

scipt ENTRYPOINT ENTRYPOINT ["sudo service docker start", "&&", "/home/user/che/bin/che.sh run"], ENTRYPOINT /bin/sh -c sudo ( ).

ENTRYPOINT Docker. , Docker:

RUN ln -sf /bin/bash /bin/sh && ln -sf /bin/bash /bin/sh.distrib

:

ENTRYPOINT ['/bin/bash', '-c']

CMD Docker /bin/bash -c.

, , , PID1, , .sh script tail -f /dev/null script, PID1 CTRL + C . .

:

[program:dcheck]
command=/bin/bash -c 'echo pid1 > /dev/null && chmod +x /root/dcheck/repo/dcheck.sh && cd /root/dcheck/repo && ./dcheck.sh'

echo pid1 > /dev/null PID1 SIGTERM, SIGKILL SIGINT script.

Docker --privileged. , .

, , , Docker . , sudo service docker start Docker?

, ? , , , , - . run, , /home/hostuser chmod +x run:

#!/bin/bash
docker run --rm -it -v /home/hostuser/your_host_shared_folder/:/root/your_container_shared_folder/:rw your_docker_image "echo pid1 > /dev/null && chmod +x /root/script.sh && cd  /root && ./script.sh"

ENTRYPOINT ENTRYPOINT ['/bin/bash', '-c'].

script :

$ cd /home/hostuser
$ ./run -flag1 -flag2 args1 args2 args3
+4

Try:
1. Dockerfile

RUN sudo chown -R user:user /home/user/che && \
    sudo service docker start
ENTRYPOINT ["/bin/sh", "-c", "/home/user/che/bin/che.sh run"]

  1. docker run -it --priviledged my/che -r:111.111.111.111
0

Source: https://habr.com/ru/post/1623525/


All Articles