diff --git a/src/Service_Command.php b/src/Service_Command.php index 9502f08..bf885b3 100644 --- a/src/Service_Command.php +++ b/src/Service_Command.php @@ -81,7 +81,8 @@ public function enable( $args, $assoc_args ) { EE::Log( 'Notice: Service nginx_proxy already enabled.' ); } } else { - $service_status = \EE\Service\Utils\init_global_container( $service ); + // Recreate, not `docker start`: an upgrade leaves a stopped service on its old image for this to move. + $service_status = \EE\Service\Utils\init_global_container( $service, '', true ); if ( $service_status ) { EE::success( sprintf( 'Service %s enabled.', $service ) ); } else { diff --git a/src/helper/service-utils.php b/src/helper/service-utils.php index 89bfe4d..9ab5512 100644 --- a/src/helper/service-utils.php +++ b/src/helper/service-utils.php @@ -76,8 +76,9 @@ function nginx_proxy_check() { * Function to start global conainer if it is not running. * * @param string $container Global container to be brought up. + * @param bool $recreate `up -d` a stopped container too, which recreates it when the compose file changed (e.g. its image). */ -function init_global_container( $service, $container = '' ) { +function init_global_container( $service, $container = '', $recreate = false ) { if ( empty( $container ) ) { $container = 'services_' . $service . '_1'; @@ -96,7 +97,14 @@ function init_global_container( $service, $container = '' ) { if ( IS_DARWIN && GLOBAL_DB === $service && ! $fs->exists( $db_conf_file ) ) { $fs->copy( SERVICE_TEMPLATE_ROOT . '/my.cnf.mustache', $db_conf_file ); } - \EE_DOCKER::boot_container( $container, \EE_DOCKER::docker_compose_with_custom() . ' up -d ' . $service ); + $up = \EE_DOCKER::docker_compose_with_custom() . ' up -d ' . $service; + if ( $recreate ) { + if ( ! EE::exec( $up ) ) { + EE::error( "There was some error in starting $container. Please check logs." ); + } + } else { + \EE_DOCKER::boot_container( $container, $up ); + } return true; } else { return false;