i am currently trying to run my Website in a Docker container using mysql and php with apache.
Docker-Compose:
version: '3.7'
services:
mysql:
image: mysql:latest
container_name: mysql
restart: always
environment:
//Database configuration variables
volumes:
- ./data/mysql/database:/var/lib/mysql
webserver:
image: php:7.4.12-apache
depends_on:
- mysql
restart: always
volumes:
- ./data/webserver:/var/www/html/
ports:
- 8888:80
command: bash -c "docker-php-ext-install mysqli && kill -HUP 1"
phpmyadmin:
depends_on:
- mysql
image: phpmyadmin:latest
container_name: phpmyadmin
links:
- mysql:db
restart: always
ports:
- 8889:80
volumes:
- /sessions
The problem began after i added the command-block to the webserver-container. Without it, the container runs perfectly and i can access the website. But with the command, the container gets stuck in a boot-loop and it seems that it tries to run the command over and over. At least thats what i guess after looking at the log of the webserver container.
However when i use docker exec -it *webserver* bash
and run the installation command directly in the container, it works perfectly. I then restart apache with kill -HUP 1
and the Website works as intended. Does anyone know what the problem is here?
My Answer:
It seems like the issue might be related to how the command is being executed in the Dockerfile. Instead of running the command in the Dockerfile, you can try running it in a separate script and then executing that script in the Dockerfile.
Here's an example of how you can modify your Dockerfile to run the installation command in a separate script:
1. Create a script file (e.g., install_mysqli.sh) with the following content:
bash
#!/bin/bash
docker-php-ext-install mysqli
kill -HUP 1
2. Update your Dockerfile to copy the script file into the container and execute it:
Dockerfile
FROM php:7.4.12-apache
COPY install_mysqli.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/install_mysqli.sh
CMD ["/usr/local/bin/install_mysqli.sh"]
By separating the installation command into a script file and executing it in the Dockerfile, you might be able to avoid the boot-loop issue. Give this approach a try and see if it resolves the problem.
Rate this post
5 of 5 based on 4528 votesComments