How to deal with state "Exit 0" in Docker
Solution 1
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 "$@"
Solution 2
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 :)
Solution 3
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.
Solution 4
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)
ReynierPM
A passionate programmer and web developer with a background in front-end and back-end development, which is what he's been doing for over eight years. I had experience in web development using PHP (mostly), MySQL and JavaScript. I follows two major principles everyday work: beauty and simplicity. I believes everyone should learn something new every day. While I'm not working, I spends time coding personal projects, learning, watching screen casts, blogging, etc. Some specific areas of interest for me include cloud computing and anything related to web development among other like system and database administration.
Updated on June 23, 2020Comments
-
ReynierPM almost 4 years
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 runningdocker-compose up -d --build
it works again.Update #1
I am not able to see such weird characters:
-
ReynierPM over 7 yearsI believe that's the issue but I don't know how to fix it, could you help me to fix this issue? I am starting to learn Docker :-)
-
BMitch over 7 yearsThe entrypoint needs to not exit, so
ENTRYPOINT /usr/local/bin/setup_php_settings && sleep infinity
may work. -
ReynierPM over 7 yearsShould I modify my
ENTRYPOIN
T to beENTRYPOINT bash -C '/usr/local/bin/setup_php_settings';'php -a'
instead? Is that what you said? -
gtonic over 7 yearsJup, but be sure also to try what VladoDemcak has found out.
-
ReynierPM over 7 yearsThat's odd. I am not seeing them, which tool did you use? I am in Fedora using Atom editor. Regarding the errors should them stop the container from start?
-
ReynierPM over 7 yearsI have updated the OP with an image, I am not able to see those weird characters
-
VladoDemcak over 7 yearsTurtoiseGit but I am on Windows. As I saw you have figured it out but it's weird.
-
VladoDemcak over 7 years@ReynierPM It is probably windows error. But when I restart container It exited with error like in your case
-
VladoDemcak over 7 years@ReynierPM I added
setup_php_settings
that worked for me also after I did restart of container without rebuild. -
abr over 3 yearsWasted 2h to find how to setup an ubuntu container because of exit code 0 and this silved the issue, thanks