1

I currently have a Docker container that runs NGINX for me. While trying to learn how to set up a proxy pass example I created a setting that crashes this container and I can no longer start the container.

Creating a new NGINX container is not a big deal, but I would like to use this example for a learning experience.

Is it possible to start up this stopped container with a different entree point rather than having it start NGINX?

I've read that I have to commit the broken container into an image and then can start up a new container from this image which I have been able to do, but this seems rather cumbersome.

If the above is the only method than I might as well just create a new container.

user179981
  • 167
  • 2
  • 5
  • 11
  • Possible duplicate of [How to start a stopped Docker container with a different command?](https://stackoverflow.com/questions/32353055/how-to-start-a-stopped-docker-container-with-a-different-command) – tgogos Oct 31 '18 at 14:40
  • The other way is to stop the docker daemon, go find the `config.json` of your container which may be somewhere here: `/var/lib/docker/containers/...`, change the `CMD` setting by editing the file, restart the deamon and then the container. – tgogos Oct 31 '18 at 14:42
  • Containers are kind of there to be deleted and recreated. If you want to debug it you can try `docker start` and other things, but if you were messing around inside the running container and it broke, just delete it and start over. – David Maze Oct 31 '18 at 15:13

1 Answers1

2

I encountered a similar problem, which can be fixed in the following ways:

  • Method 1: based on docker cp, copy the file contents of the damaged container to the current environment (even if the container cannot be started);
  • Method 2: based on docker commit resubmit the damaged container as another image, and then start the additional entry point entry;

Note: the above methods are just a few tricks to use during debugging or development, and eventually we should write the related operations into the Dockerfile configuration or docker-compose.yml configuration.

Fix Progress:

  1. Because I temporarily modified the ./php-fpm.d/www.conf configuration in my PHP-FPM container, the container could not be started:
$ docker-compose ps
     Name                   Command                State                Ports
----------------------------------------------------------------------------------------
phpfpm_fpm_1     docker-php-entrypoint php-fpm   Restarting
phpfpm_nginx_1   nginx -g daemon off;            Up           80/tcp, 0.0.0.0:86->86/tcp
  1. Check related error information by docker-compose log-f:
fpm_1    | [03-Dec-2019 03:57:50] ERROR: Unable to create or open slowlog(/usr/local/log/www.log.slow): No such file or directory (2)
fpm_1    | [03-Dec-2019 03:57:50] ERROR: Unable to create or open slowlog(/usr/local/log/www.log.slow): No such file or directory (2)
fpm_1    | [03-Dec-2019 03:57:50] ERROR: failed to post process the configuration
fpm_1    | [03-Dec-2019 03:57:50] ERROR: failed to post process the configuration
fpm_1    | [03-Dec-2019 03:57:50] ERROR: FPM initialization failed
fpm_1    | [03-Dec-2019 03:57:50] ERROR: FPM initialization failed
fpm_1    | [03-Dec-2019 03:58:51] ERROR: Unable to create or open slowlog(/usr/local/log/www.log.slow): No such file or directory (2)
fpm_1    | [03-Dec-2019 03:58:51] ERROR: Unable to create or open slowlog(/usr/local/log/www.log.slow): No such file or directory (2)
fpm_1    | [03-Dec-2019 03:58:51] ERROR: failed to post process the configuration
fpm_1    | [03-Dec-2019 03:58:51] ERROR: failed to post process the configuration
fpm_1    | [03-Dec-2019 03:58:51] ERROR: FPM initialization failed
fpm_1    | [03-Dec-2019 03:58:51] ERROR: FPM initialization failed
  1. Check the configuration information manually debugged in the container by docker diff container-id:
$ docker ps -a|grep php
5dfe26f00059        tkstorm/phpngx               "nginx -g 'daemon of…"   2 weeks ago         Up 41 hours                     80/tcp, 0.0.0.0:86->86/tcp                                                                   phpfpm_nginx_1
6f8a2044ba36        tkstorm/phpfpm               "docker-php-entrypoi…"   2 weeks ago         Restarting (78) 7 seconds ago                                                                                                phpfpm_fpm_1
  1. Copy the wrong ./php-fpm.d/www.conf configuration that damaged the container to the local directory and fix it:
$ docker cp phpfpm_fpm_1:/usr/local/etc/php-fpm.d/www.conf fix-www.conf

$ vi fix-www.conf
...
slowlog = /var/log/$pool.log.slow
...
  1. Copy the repaired configuration to the damaged container again:
// after fix up
$ docker cp fix-www.conf phpfpm_fpm_1:/usr/local/etc/php-fpm.d/www.conf
  1. Restart the container:
$ docker restart phpfpm_fpm_1

// it' fix ok
$ docker-compose ps
     Name                   Command              State             Ports
-----------------------------------------------------------------------------------
phpfpm_fpm_1     docker-php-entrypoint php-fpm   Up      9000/tcp
phpfpm_nginx_1   nginx -g daemon off;            Up      80/tcp, 0.0.0.0:86->86/tcp
lupguo
  • 1,525
  • 13
  • 13