Containers playground - Quick testing
170
https://github.com/labolida/php-test-connectivity/
docker push lmldocker/php-test-connectivity:2.0
Test containers connectivity retrieving text value from one container to another one. Example: First container request via HTTP a text content from a certain URL. You can deploy 2 containers to make this communication as an example.
index.php
<?php
echo "php is up!";
$TEST_HOST = $_ENV["TEST_HOST"];
$TEST_PORT = $_ENV["TEST_PORT"];
$TEST_ENDPOINT = $_ENV["TEST_ENDPOINT"];
echo "<br> ENV TEST_HOST:" . $TEST_HOST;
echo "<br> ENV TEST_PORT:" . $TEST_PORT;
echo "<br> ENV TEST_ENDPOINT:" . $TEST_ENDPOINT;
$remote_file_name="http://$TEST_HOST:$TEST_PORT/$TEST_ENDPOINT";
echo "<br> remote_file_name:" . $remote_file_name;
echo "<br> Testing connectivity with other php-container";
echo "<br> Opening remote file:";
$fp = fopen ( $remote_file_name, "r" );
if (!$fp) {
echo "<br> ERROR Unable to open remote file " . $remote_file_name ;
exit;
}
while ( ! feof ($fp) ) {
#$line = fgets ($file, 1024);
$content .= fread( $fp, 1024 /*filesize($filename)*/ );
}
echo "<br> REMOTE_CONTENT:";
echo "<hr>" . $content;
fclose($fp);
?>
remote-content.php
<?php
echo $_ENV["TEST_CONTENT"];
?>
001
docker run --name php-test-001 \
-p 5580:80 \
--env TEST_HOST=192.168.1.9 \
--env TEST_PORT=5581 \
--env TEST_ENDPOINT=remote-content.php \
--env TEST_CONTENT='I-am-php-test-001-contanier-port-5580' \
--cpus="0.5" \
--memory="50m" --memory-reservation="50m" \
--rm \
lmldocker/php-test-connectivity:2.0
002
docker run --name php-test-002 \
-p 5581:80 \
--env TEST_HOST=192.168.1.9 \
--env TEST_PORT=5580 \
--env TEST_ENDPOINT=remote-content.php \
--env TEST_CONTENT='I-am-php-test-002-contanier-port-5581' \
--cpus="0.5" \
--memory="50m" --memory-reservation="50m" \
--rm \
lmldocker/php-test-connectivity:2.0
Feel free to change it to use --restart=always and detached mode -d where in this case don't forget to remove the --rm remove option.
Web is up! php is up!
ENV TEST_HOST:192.168.1.9
ENV TEST_PORT:5581
ENV TEST_ENDPOINT:remote-content.php
remote_file_name:http://192.168.1.9:5581/remote-content.php
Testing connectivity with other php-container
Opening remote file:
REMOTE_CONTENT:I-am-php-test-002-contanier-port-5581
Web is up! php is up!
ENV TEST_HOST:192.168.1.9
ENV TEST_PORT:5580
ENV TEST_ENDPOINT:remote-content.php
remote_file_name:http://192.168.1.9:5580/remote-content.php
Testing connectivity with other php-container
Opening remote file:
REMOTE_CONTENT:I-am-php-test-001-contanier-port-5580
apiVersion: v1
kind: Pod
metadata:
name: php-test-001-pod
namespace: test
labels:
tag-name: php-test-001-tag
spec:
containers:
- name: php-test-001-container
image: lmldocker/php-test-connectivity:2.0
ports:
- containerPort: 80
env:
- name: TEST_HOST
value: "php-test-002-svc"
- name: TEST_PORT
value: "80"
- name: TEST_ENDPOINT
value: "remote-content.php"
- name: TEST_CONTENT
value: "I-am-php-test-001-contanier"
---
apiVersion: v1
kind: Pod
metadata:
name: php-test-002-pod
namespace: test
labels:
tag-name: php-test-002-tag
spec:
containers:
- name: php-test-002-container
image: lmldocker/php-test-connectivity:2.0
ports:
- containerPort: 80
env:
- name: TEST_HOST
value: "php-test-001-svc"
- name: TEST_PORT
value: "80"
- name: TEST_ENDPOINT
value: "remote-content.php"
- name: TEST_CONTENT
value: "I-am-php-test-002-contanier"
---
apiVersion: v1
kind: Service
metadata:
name: php-test-001-svc
namespace: test
spec:
selector:
tag-name: php-test-001-tag
ports:
- protocol: TCP
port: 80
#targetPort: 80
#type: NodePort
---
apiVersion: v1
kind: Service
metadata:
name: php-test-002-svc
namespace: test
spec:
selector:
tag-name: php-test-002-tag
ports:
- protocol: TCP
port: 80
by leonardo.labolida.com -- 04-JAN-2023
Content type
Image
Digest
sha256:0c2cf1cd4…
Size
158.7 MB
Last updated
over 3 years ago
docker pull lmldocker/php-test-connectivity:3.0