I wrote "docker-compose.yml", and I want to execute two commands:
uwsgi -i /code/uwsgi.ini and python3.6 /code/manage.py collectstatic
I tried to use && to connect the two command, but it failed, what can I do?
You can execute multiple commands using bash -c:
command: >
bash -c "uwsgi -i /code/uwsgi.ini
&& python3.6 /code/manage.py collectstatic"
Related
I want to run a temporary docker and execute several command in it:
.PHONY : Test
Test:
#echo Starting Docker container
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run -b '$(PRJ_BUILD_TREE)' -w '$(PRJ_WORK_DIR)' --objdir '' -c 'rm -rf build_results; \
make clean_brutal; \
$(PRJ_MISRA_CMD)/cov-build --dir build_results --encoding UTF-8 make SUB_PRODUCT=$(SUB_PRODUCT); \
$(if $(COVERITY_MISRA_2012), \
$(PRJ_test_CMD)/cov-analyze --dir build_results --disable-default --coding-standard-config /home/XX/XX-linux64-2018.06/config/coding-standards/XX/XX-all.config --paths 100000 --tu-pattern "file('.*\.c$\')"; \
$(PRJ_test_CMD)/cov-format-errors --dir build_results --html-output build_results/results/HTML_2012, );'
but I het the following error:
Illegal character in pattern: .
[ERROR] No results found.
I want to know how to run command seperately in a running container?
like:
.PHONY : Test
Test:
#echo Starting Docker container
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run -b '$(PRJ_BUILD_TREE)' -w '$(PRJ_WORK_DIR)' --objdir '' -c 'rm -rf build_results; \
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run -c 'make clean_brutal';
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run -c '$(PRJ_MISRA_CMD)/cov-build --dir build_results --encoding UTF-8 make SUB_PRODUCT=$(SUB_PRODUCT)'
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run -c '$(if $(FFFF), \
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run $(PRJ_test_CMD)/cov-analyze --dir build_results --disable-default --coding-standard-config /home/XX/XX-linux64-2018.06/config/coding-standards/XX/XX-all.config --paths 100000 --tu-pattern "file('.*\.c$\')"'
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run -c '$(PRJ_test_CMD)/cov-format-errors --dir build_results --html-output'build_results/results/HTML_2012, );'
I know this doesn't work but to give an idea what I want to do
I'm using the jonasal/nginx-certbot:latest to run several services under NGINX with automatic certificate generation.
I now want to create a second instance for UAT testing where all domains shift from [subdomain].domain.com to [subdomain]-uat.domain.com. To enable this I have substituted the domains by environment variables and used the following command in the docker-compose.yaml file:
command: /bin/bash -c "envsubst < /etc/nginx/user_conf.d/ssl-server.conf.template > /etc/nginx/user_conf.d/ssl-server.conf && nginx -g 'daemon off;'
This produces the correct ssl_server.conf file but does not seem to start the certbot process.
I'm trying to figure out if using a command in the docker-compose.yaml overrules the RUN command in the Dockerfile but cannot find anything to say that.
I'm also trying to trigger the run command from within the docker-compose.yaml file like.
command: /bin/bash -c "envsubst < /etc/nginx/user_conf.d/ssl-server.conf.template > /etc/nginx/user_conf.d/ssl-server.conf && nginx -g 'daemon off;' && /scripts/start_nginx_certbot.sh"
But this does not make a difference.
What am I missing?
Your command overrides the command in the image, so you need to run the startup script yourself as you show in your last command.
I think your error in that is that you also run nginx. When you do it that way, your 'base' nginx starts and since it doesn't exit, the normal startup script is never run. Try this
command: /bin/bash -c "envsubst < /etc/nginx/user_conf.d/ssl-server.conf.template > /etc/nginx/user_conf.d/ssl-server.conf && /scripts/start_nginx_certbot.sh"
I am using docker on windows - version 18.03 (client)/18.05 (server). I have created docker-compose file for ELK stack. Everything is working fine. What I would like to do is, to install logtrail before kibana is started. I was thinking about copying logtrail*.zip first, then call install:
container_name: kibana
(...)
command:
- docker cp kibana:/ ./kibana/logtrail/logtrail-6.7.1-0.1.31.zip
- /bin/bash
- ./bin/kibana-plugin install/logtrail-6.7.1-0.1.31.zip
But that doesn't look like right way as first of all it doesn't work, second of all I am not sure if I can call mutliple commands like I did and third of all I'm not sure if docker cp in command is even allowed on that stage of service creation
command:
- /bin/bash
- -c
- |
echo "This is a multiline command"
echo "See how I escape $$ sign"
echo $$PATH
You can run multiple commands like above however you can not run docker cp as in your command.
You can run multiple commands for a service in docker compose by:
command: sh -c "command1 && command2 && command2"
THATS MY SOLUTION FOR THIS CASE:
# OPTION 01:
# command: >
# bash -c "chmod +x /scripts/rs-init.sh
# && sh /scripts/rs-init.sh"
# OPTION 02:
# entrypoint: [ "bash", "-c", "chmod +x /scripts/rs-init.sh && sh /scripts/rs-init.sh"]
If you're looking to install software David Maze's comment seems to be the standard path. If you want to actually run multiple commands look at the answer to this SO question Using Docker-Compose, how to execute multiple commands
I try to build a custom image for the EMQ MQTT server. But the script update_config.sh is not executed by during docker copmose up.
Dockerfile:
FROM emqttd-docker-v2.3.5
# change configuration file
ADD update_config.sh /opt/emqttd/etc/update_config.sh
ADD ./certs/MyEMQ1.key /opt/emqttd/etc/certs/MyEMQ1.key
ADD ./certs/MyEMQ1.pem /opt/emqttd/etc/certs/MyEMQ1.pem
ADD ./certs/MyRootCA.pem /opt/emqttd/etc/certs/MyRootCA.pem
WORKDIR /opt/emqttd/etc/
#update the emqtt config file
RUN /bin/ash -c /opt/emqttd/etc/update_config.sh
update_config.sh
#!/bin/ash
cd /opt/emqttd/etc
cp ./emq.conf ./emq.conf.bak
sed -i 's|.*listener.ssl.external.keyfile.*|listener.ssl.external.keyfile = etc/certs/MyEMQ1.key|g' ./emq.conf
sed -i 's|.*listener.ssl.external.certfile.*|listener.ssl.external.certfile = etc/certs/MyEMQ1.pem|g' ./emq.conf
sed -i 's|.*listener.ssl.external.cacertfile.*|listener.ssl.external.cacertfile = etc/certs/MyRootCA.pem|g' ./emq.conf
sed -i 's|.*listener.ssl.external.verify.*|listener.ssl.external.verify = verify_peer|g' ./emq.conf
I use docker-compose to build the image.
The update_config.sh script is copied to the image but not executed.
What I tried so far:
Used COPY instead of ADD to copy the file
Tried the RUN /bin/ash -c /opt/emqttd/etc/update_config.sh in the following
flavors:
RUN /bin/ash -c /opt/emqttd/etc/update_config.sh
RUN /opt/emqttd/etc/update_config.sh
RUN ./update_config.sh
Tried to add RUN chmod +x /opt/emqttd/etc/update_config.sh before the line RUN /bin/ash -c /opt/emqttd/etc/update_config.sh which results in the error chmod: /opt/emqttd/etc/update_config.sh: Operation not permitted during build
Can anyone help me? Thanks.
Just add ENTRYPOINT ["/bin/bash", "update_config.sh" ] this as your last line.
And also update_config.sh file to start your application and make your container in infinite loop.
Example update_config.sh:
#!/bin/ash
cd /opt/emqttd/etc
cp ./emq.conf ./emq.conf.bak
sed -i 's|.*listener.ssl.external.keyfile.*|listener.ssl.external.keyfile = etc/certs/MyEMQ1.key|g' ./emq.conf
sed -i 's|.*listener.ssl.external.certfile.*|listener.ssl.external.certfile = etc/certs/MyEMQ1.pem|g' ./emq.conf
sed -i 's|.*listener.ssl.external.cacertfile.*|listener.ssl.external.cacertfile = etc/certs/MyRootCA.pem|g' ./emq.conf
sed -i 's|.*listener.ssl.external.verify.*|listener.ssl.external.verify = verify_peer|g' ./emq.conf
sh start_your_app.sh
touch 1.txt;tail -f 1.txt #This will make your container in running infinite so that even after all the steps of this script has been executed your container will continue running. until you kill tail -f 1.txt command.
Hope this will help.
Thank you!
ash - is one of the smallest shells. This command interpreter has 24 built-in commands and 10 different command-line options.
ash hasn't all commands which you need. You should use /bin/bash
I have build a Docker image and afterwards run a container using Docker Compose. The following command will do the job for me:
docker-compose up -d
I have restarted the PC and now I want to start the previous container that I've created before. So I have tried the following command:
$ docker-compose start
Starting php-apache ... done
Apparently it works but it doesn't as per the output for the following command:
$ docker-compose ps
Name Command State Ports
---------------------------------------------------------------------------
php55devwork_php-apache_1 /bin/sh -c bash -C '/usr/l ... Exit 0
For sure something is wrong and I am trying to find out what.
How do I find why the command is failing?
Is there any place where I could see a log file or something that help me to identify and fix the error?
Here is the repository if you want to give it a try.
Update
If I remove the container: docker rm <container-id> and recreate it by running docker-compose up -d --build it works again.
Update #1
I am not able to see such weird characters:
This is what helped me to resolve this issue:
Under one of your services in the docker-compose yaml file, type in the following:
tty: true so it'll look like
version: '3'
services:
web:
tty: true
Hopefully this helps someone; thumps up if it helps you :)
I took a look into your Docker github and setup_php_settings
on line (line n. 27) there is source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND
and that runs apache2 on foreground so it shouldn't exit with status code 0.
But it seems to me like your setup_php_settings contains some weird character (when I run your image with compose)
(original is one on right side) weird character
I have changed it to new lines and it worked for me. Let us know if it helped.
If you want to debug your docker container you can run it without entrypoint like:
docker run -it yourImage bash
-- AFTER some investigation:
There were still some errors when I restart docker container - like in your case stopped container and start after reboot. There were problems: symbolic links already exist and apache2 has grumpy PID so we need to do something like in oficial php docker
This is full setup_php_settings worked for me after container restart.
#!/bin/bash -x
set -e
PHP_ERROR_REPORTING=${PHP_ERROR_REPORTING:-"E_ALL & ~E_DEPRECATED & ~E_NOTICE"}
sed -ri 's/^display_errors\s*=\s*Off/display_errors = On/g' /etc/php5/apache2/php.ini
sed -ri 's/^display_errors\s*=\s*Off/display_errors = On/g' /etc/php5/cli/php.ini
sed -ri "s/^error_reporting\s*=.*$//g" /etc/php5/apache2/php.ini
sed -ri "s/^error_reporting\s*=.*$//g" /etc/php5/cli/php.ini
echo "error_reporting = $PHP_ERROR_REPORTING" >> /etc/php5/apache2/php.ini
echo "error_reporting = $PHP_ERROR_REPORTING" >> /etc/php5/cli/php.ini
mkdir -p /data/tmp/php/uploads
mkdir -p /data/tmp/php/sessions
mkdir -p /data/tmp/php/xdebug
chown -R www-data:www-data /data/tmp/php*
ln -sf /etc/php5/mods-available/zz-php.ini /etc/php5/apache2/conf.d/zz-php.ini
ln -sf /etc/php5/mods-available/zz-php-directories.ini /etc/php5/apache2/conf.d/zz-php-directories.ini
# Add symbolic link to get Zend out of the current install dir
ln -sf /usr/share/php/libzend-framework-php/Zend/ /usr/share/php/Zend
a2enmod rewrite
php5enmod mcrypt
# Apache gets grumpy about PID files pre-existing
: "${APACHE_PID_FILE:=${APACHE_RUN_DIR:=/var/run/apache2}/apache2.pid}"
rm -f "$APACHE_PID_FILE"
source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND "$#"
You can check logs with docker compose logs.
Looking through your repo, you have
ENTRYPOINT bash -C '/usr/local/bin/setup_php_settings';'bash'
which, without an interactive session, bash will exit immediately (with an exit code 0) after reading the end of file on stdin.
Normally getting an exit 0 should be a reason to celebrate, as it indicates that your command has ended successfully (http://www.tldp.org/LDP/abs/html/exit-status.html).
Having had a look at your Dockerfile it looks like, your just invoking bash in your entry point which then for sure will exit (as it is non blocking). In order to serve some data, you should rather be calling php (which is a blocking operation that keeps the container up), like done in the official docker files for php (see the CMD ["php", "-a"] at https://github.com/docker-library/php/blob/1c56325a69718a3e3cf76179e75d070b7e23da62/5.6/Dockerfile)