thanks for taking some time to read over this question. I have code written in PHP, HTML, CSS,
Javascript and MySQL on a development computer. this code runs fine. No errors shown.
I wanted to move my code to a docker swarm. I made a docker compose file (FIG 1) and launched
to my docker swarm specs shown(FIG 2). the swarm stack runs perfectly but when i went to add
my code to the volume connected to /var/www/html it shows incorrectly with error upon error
(FIG 3).
I have tried to provide any valuable information to crack this question. If there is anything i
am missing or if there is too much info?!? Let me know.
Thanks in advance.
Docker (FIG 1 && FIG 2)
version: "3.8"
services:
loadbalancer:
image: nginx
ports:
- "80:80"
networks:
- frontend
- backend
deploy:
mode: global
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
web:
image: php:8.0-rc-apache-buster
ports:
- "8080:80"
networks:
- backend
deploy:
mode: global
volumes:
- ./code:/var/www/html/
- ./apache2.conf:/var/apache2/apache2.conf
mariadb:
image: linuxserver/mariadb:arm32v7-latest
ports:
- "8081:80"
networks:
- backend
volumes:
- ./data:/config/databases
deploy:
placement:
constraints:
- node.hostname==dot5
phpmyadmin:
image: phpmyadmin
ports:
- 8000:80
environment:
- PMA_ARBITRARY=1
- PMA_HOST=mariadb
depends_on:
- mariadb
deploy:
mode: global
networks:
- backend
- frontend
networks:
frontend:
backend:
Client:
Debug Mode: false
Server:
Containers: 3
Running: 3
Paused: 0
Stopped: 0
Images: 11
Server Version: 19.03.13
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: active
NodeID: 101slznkwl25s4pejtngbrq0z
Is Manager: true
ClusterID: jphdf0tzm4p37i7xail1mcoiq
Managers: 4
Nodes: 8
Default Address Pool: 10.0.0.0/8
SubnetSize: 24
Data Path Port: 4789
Orchestration:
Task History Retention Limit: 5
Raft:
Snapshot Interval: 10000
Number of Old Snapshots to Retain: 0
Heartbeat Tick: 1
Election Tick: 10
Dispatcher:
Heartbeat Period: 5 seconds
CA Configuration:
Expiry Duration: 3 months
Force Rotate: 0
Autolock Managers: false
Root Rotation In Progress: false
Node Address: 192.168.0.109
Manager Addresses:
192.168.0.102:2377
192.168.0.103:2377
192.168.0.109:2377
192.168.0.86:2377
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 8fba4e9a7d01810a393d5d25a3621dc101981175
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 5.4.51-v7+
Operating System: Raspbian GNU/Linux 10 (buster)
OSType: linux
Architecture: armv7l
CPUs: 4
Total Memory: 975.4MiB
Name: dot3
ID: UZO6:MLFS:W2AW:EFAI:2KXY:XQNE:3K2S:CEND:JQCY:EVVH:HEEW:ICOM
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No memory limit support
WARNING: No swap limit support
WARNING: No kernel memory limit support
WARNING: No kernel memory TCP limit support
WARNING: No oom kill disable support
WARNING: No cpu cfs quota support
WARNING: No cpu cfs period support
PHP code (FIG 3)
<div class='row justify-content-center mart' id="items">
<!-- connect -->
<?php
include_once 'con.php';
global $conn;
$filter = "";
if (isset($_GET['all'])) {
$filter = "";
}
else if (isset($_GET['household'])) {
$filter = "WHERE type = 'household'";
}
else if (isset($_GET['weed'])) {
$filter = "WHERE type = 'weed'";
}
else if (isset($_GET['garden'])) {
$filter = "WHERE type = 'garden'";
}
else if (isset($_GET['dessert'])) {
$filter = "WHERE type = 'dessert'";
}
else if (isset($_GET['tech'])) {
$filter = "WHERE type = 'tech'";
}
else if (isset($_GET['bants'])) {
$filter = "WHERE type = 'bants'";
}
$sql = "SELECT * FROM items $filter";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_array($result)) {
?>
<div class="col-lg-4 col-md-6 col-sm-6 col-xs-12 col-12 mb-4">
<a href="<?php printf('%s?item_id=%s', 'view.php', $row['item_id'])?>">
<div class='menu_item sharp-rounded slight-hover'>
<div class="card-img-top-left">
<i <?php echo 'class="fas fa-'.$row['fa'].' fa-2x text-orange"'; ?>></i>
</div>
<img class='menu-img sharp-rounded marb' style="max-height: 600px; max-width: 100%; width: auto;" id="loading-item" src='<?php echo str_replace("../", "assets/", $row["image"]);?>' alt='<?php echo $row['name']; ?>'>
<div class="row justify-content-center">
<div class="col-md-6 mart">
<h4 style="color: #e84545;">$<?php echo $row['price']; ?></h4>
</div>
<div class="col-md-6 mart text-orange">
<a href="view.php?item_id=<?php echo $row['item_id']; ?>#add_to_cart">Add To Cart</a>
</div>
<div class="inline-block" style="width: 100%;">
<h4><?php echo $row['name'];?></h4>
<p style="color:#686E79; overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 5;
-webkit-box-orient: vertical;">
<?php echo $row['info']; ?>
</p>
</div>
</div>
</div>
</a>
</div>
<?php
}} else { ?>
<div class="bob"><img class="sharp-rounded" src="assets/images/gen/nothing_here.png" alt="nothing here!" width="70%"></div>
<?php
} mysqli_close($conn);
?>
</div>
Expectied look of the site. 1: docker-stack 2: rpi development server
2
Answers
Issue resolved.
It turns out that mysqli is required to make my application run (it is not installed by default!).
Thank you all.
The Docker image you are using for your web container at least does not have the mysqli plugin enabled(hence the undefined function). You can enable that in a Dockerfile using
docker-php-ext-install
anddocker-php-ext-enable
in the official PHP base image.https://github.com/docker-library/docs/tree/master/php#php-core-extensions
https://github.com/docker-library/php/issues/391
Once that is resolved, there may be other issues, but that is the immediate problem.