Jared
Jared

Reputation: 163

Docker stack: Apache service will not start

Apache service in docker stack never starts (or, to be more accurate, keeps restarting). Any idea what's going on?

The containers are the ones in: https://github.com/adrianharabula/lampstack.git

My docker-compose.yml is:

version: '3'

services:
   db:
     image: mysql:5.7
     volumes:
       - ../db_files:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: toor
       #MYSQL_DATABASE: testdb
       #MYSQL_USER: docky
       #MYSQL_PASSWORD: docky
     ports:
      - 3306:3306
   p71:
#     depends_on:
#       - db
     image: php:7.1
     build:
      context: .
      dockerfile: Dockerfile71
     links:
      - db
     volumes:
      - ../www:/var/www/html
      - ./php.ini:/usr/local/etc/php/conf.d/php.ini
      - ./virtualhost-php71.conf:/etc/apache2/sites-available/001-virtualhost-php71.conf
      - ../logs/71_error.log:/var/www/71_error.log
      - ../logs/71_access.log:/var/www/71_access.log
     environment:
       DB_HOST: db:3306
       DB_PASSWORD: toor
     ports:
      - "81:80"

   pma:
     depends_on:
       - db
     image: phpmyadmin/phpmyadmin

And I start it with:

docker stack deploy -c docker-compose.yml webstack

db and pma services start correctly, but p71 service keeps restarting

docker service inspect webstack_p71

indicates:

    "UpdateStatus": {
        "State": "paused",
        "StartedAt": "2018-01-19T16:28:17.090936496Z",
        "CompletedAt": "1970-01-01T00:00:00Z",
        "Message": "update paused due to failure or early termination of task 45ek431ssghuq2tnfpduk1jzp"
    }

As you can see by the docker-composer.yml I already commented out the service dependency to avoid failures if dependencies are not met at first run.

$ docker service logs -f webstack_p71

docker service logs -f webstack_p71

$ docker service ps --no-trunc webstack_p71

docker service ps --no-trunc webstack_p71

What should I do to get that Apache/PHP (p71) service running?

All the containers work when run independently: $ docker build -f Dockerfile71 -t php71 . $ docker run -d -p 81:80 php71:latest

Upvotes: 3

Views: 496

Answers (1)

SangminKim
SangminKim

Reputation: 9136

First of all, depends_on option doesn't work in swarm mode of version 3.(refer this issue)

In short...

depends_on is a no-op when used with docker stack deploy. Swarm mode services are restarted when they fail, so there's no reason to delay their startup. Even if they fail a few times, they will eventually recover.

Of course, even though depends_on doesn't work, p71 should work properly since it would restart after the failure.

Thus, I think there is some error while running p71 service. that would be why the service keeps restarting. however, I am not sure what is happening inside the service only with the information you offer.

You could check the trace by checking log.

$ docker service logs -f webstack_p71

and error message

$ docker service ps --no-trunc webstack_p71   # check ERROR column

Upvotes: 3

Related Questions