Skip to content

Commit

Permalink
docker environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
jambtc committed Mar 25, 2021
1 parent 0b5ca79 commit 892aab6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ RUN apt-get install openssh-server sudo -y
RUN service ssh start
#RUN apt-get install -y net-tools

EXPOSE 22


COPY assets /var/www/assets
COPY commands /var/www/commands
COPY components /var/www/components
Expand All @@ -34,3 +31,6 @@ RUN chmod +x /var/www/yii

RUN mv /var/www/config/db-docker.php /var/www/config/db.php
RUN chown -R www-data:www-data /var/www

EXPOSE 22
ENV DOCKERCONTAINER=true
9 changes: 8 additions & 1 deletion components/Seclib.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ public function execInBackground($cmd)
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
} else {
$ssh = new \phpseclib\Net\SSH2('172.18.0.1', 22);
// determine whether we are running in a docker container
if (isset($_ENV['DOCKERCONTAINER']) && $_ENV['DOCKERCONTAINER'] == true){
$host_address = $_SERVER['REMOTE_ADDR'];
} else {
$host_address = 'localhost';
}

$ssh = new \phpseclib\Net\SSH2($host_address, 22);
if (!$ssh->login(WebApp::decrypt(Settings::load()->sshuser), WebApp::decrypt(Settings::load()->sshpassword))) {
return array('error' => 'Login to localhost server failed');
}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: '3'
services:
yii2-php:
yii2:
#image: yiisoftware/yii2-php:7.2-apache
build: .
volumes:
Expand Down
3 changes: 3 additions & 0 deletions web/phpinfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

phpinfo(); ?>

0 comments on commit 892aab6

Please sign in to comment.