I
I
Ivanoff-i2016-04-13 13:45:31
Docker
Ivanoff-i, 2016-04-13 13:45:31

How to automatically start services on container startup in docker?

There is an autorun task inside the redis container and a few more commands, decorated in a bash script. These commands are dynamic. This is how the contents of the bash file are formed from under php

$queue = <<<QUEUE
#!/bin/bash

eval \"QUEUE='{$params['hostname']}_1' COUNT=1 php /root/tracker/resque >> /var/log/resque_worker.log 2>&1 &\"
eval \"QUEUE='{$params['hostname']}_2' COUNT=1 php /root/tracker/resque >> /var/log/resque_worker.log 2>&1 &\"
eval \"QUEUE='{$params['hostname']}_3' COUNT=1 php /root/tracker/resque >> /var/log/resque_worker.log 2>&1 &\"

eval \"php /root/start-workers.php\"

QUEUE;

those. when deployed to each server, they will be different. All this should be launched automatically when the container starts. Tried through run --entrypoint, but when starting the container, it constantly has the restarting status. How to properly organize it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nazar Mokrinsky, 2016-04-14
@nazarpc

Не вижу в командах ничего динамического кроме нескольких аргументов - eval тут совершенно не нужен.
ПО поводу ошибок - смотрите docker logs container_name, там будет писать если что вывалилось в stderr.

Егор Ш., 2016-04-13
@EgorkZe

Я запускаю sh скрипты так - CMD /etc/nginx/config.sh

I
Ivanoff-i, 2016-04-14
@Ivanoff-i Автор вопроса

CMD - это в Dockerfile. А как эту задачу решить при run контейнера? Например, пишу docker run -td --restart=always --net=host -p 6379 -e SERVER_IP=xx.xx.xx.xx --name name image-name /etc/init.d/redis-server start
Если верить документации docker run [OPTIONS] IMAGE [COMMAND] [ARG...] после IMAGE стоит COMMAND, на его место ставлю /etc/init.d/redis-server start, но тогда у контейнера постоянно статус restarting

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question