I am very new to Docker so please forgive any technical wording mistakes I make regarding this.
I am trying to get a very basic "Hello World!" php script to run through a localhost docker container. I am trying to run this script to test out this image that contains php and oracle: https://hub.docker.com/r/silencesys/php-oci8
I pulled it using this command: docker pull silencesys/php-oci8
Then I tried to run it with numerous commands, some of them giving me this:
[16-Jun-2022 17:57:12] NOTICE: fpm is running, pid 1
[16-Jun-2022 17:57:12] NOTICE: ready to handle connections
And then some of them give a random string of letters and numbers. I don't know what it refers to but I know that it means that it is running the container. When I open the container's terminal and run 'ls' I can see my index.php file. I can even run 'cat index.php' and see that it contains the proper code in there to run "Hello World!" I will even include the code in here as a sanity check:
<?php
echo "Hello World!";
?>
But everytime that I open up the localhost in my browser, I get this:
This page isn’t working right now
localhost didn’t send any data.
ERR_EMPTY_RESPONSE
I have tried so many variations of this base docker run command that I found here:
docker run -d -p 80:80 --rm --name temp-container -v "$PWD":/var/www/html silencesys/php-oci8
Any help is greatly appreciated!
The docker image you are referring to does contain PHP, but it does not contain a web server.
Servers that serve web pages using PHP consist of a webserver software, that accepts HTTP-requests and communicates to PHP running in the background if needed. It can be thought of an intermediary between the Browser and PHP, and if it is missing the browser cannot access your PHP script.
I haven't found an image that could help you right away, however I stumbled upon this, and it tells that for your usecase you should go for a PHP image that has Apache included (i.e. the name will contain apache in the tag).
The way I solved this was by using this image in conjunction with the image I was using in the Question. Here is a step by step guide of what I did:
Create folder in home/[username] directory
docker pull soivangoi/nginx-php-adminer-oci8
docker pull silencesys/php-oci8
docker run -dit -p 8080:80 soivangoi/nginx-php-adminer-oci8 -v "$PWD":/var/www/ silencesys/php-oci8
4.1. If that doesn't work try this "docker run -d -it -p 8080:80 -v "$PWD":/var/www/ silencesys/php-oci8"
docker run -it -p 8080:80 --rm --name test-container -v "$PWD":/var/www/ soivangoi/nginx-php-adminer-oci8
Bash into the container. Either by command line or by clicking the terminal button on the container.
cd to where your php code is stored.
Run it!
Just make sure that whatever network you are on has access to the oracle database or else it will not let you run your code still.
Related
I got a working php-fpm docker container acting as the php backend to a nginx frontend. What I mean by working, is that it renders phpinfo output in the browser as expected.
My php-fpm container was produced by php-fpm-7.4 prod of the devilbox docker repo. It has OCI8 enable.
The issue: I keep getting ORA-28547 when trying oci_connect
What I have done:
1--add /usr/lib/oracle/client64/lib to a file inside ld.so.conf.d and run ldconfig -v
2--restart docker container.
3-- Now phpinfo shows ORACLE_HOME=/usr/lib/oracle/client64/lib
4--Add tnsnames.ora to /usr/lib/oracle/client6/lib/network/admin (there is a README.md file inside that folder that even tells you to do that)
5--Restart docker container again.
6-oci_connect still fails with the same error.
What I am missing?
Thank you very much for any pointers, I think I have browsed to the end of the internet and back without finding a solution yet.
----SOLUTION: reinstall instantclient, relink libraries (ldconfig) to use new instantclient libraries. Create modified dockerfile to do it when container is created.
I modified the Dockerfile file of the php-fpm to add new instant client files and not the one that were provided by the original file. I was not able to make it work with them. I have tried a few times rebuilding the image (docker-compose up --build) and this is the file that does the trick:
FROM devilbox/php-fpm:7.4-work
#instantclient.conf content: /opt/instantclient
RUN echo "/opt/instantclient" >/etc/ld.so.conf.d/instantclient.conf
WORKDIR /opt
RUN wget https://download.oracle.com/otn_software/linux/instantclient/19800/instantclient-sdk-linux.x64-19.8.0.0.0dbru.zip
RUN wget https://download.oracle.com/otn_software/linux/instantclient/19800/instantclient-sqlplus-linux.x64-19.8.0.0.0dbru.zip
RUN wget https://download.oracle.com/otn_software/linux/instantclient/19800/instantclient-basic-linux.x64-19.8.0.0.0dbru.zip
RUN unzip instantclient-sdk-linux.x64-19.8.0.0.0dbru.zip
RUN unzip instantclient-sqlplus-linux.x64-19.8.0.0.0dbru.zip
RUN unzip instantclient-basic-linux.x64-19.8.0.0.0dbru.zip
RUN mv instantclient_19_8 instantclient
ADD tnsnames.ora /opt/instantclient/network/admin
RUN ldconfig -v
CMD ["php-fpm"]
expose 9000
# Insert following to .bash_profile or .profile of the User starting the php-fpm
export ORACLE_HOME=/usr/lib/oracle/client64
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export PATH=$PATH:$ORACLE_HOME/bin
export TNS_ADMIN=$ORACLE_HOME/network/admin
# Test to Ping Remote Db to be connected by PHP
tnsping <tns-name of remote DB - i.e. db12c.world>
# restart here the php Engine
Can you please check
https://github.com/caffeinalab/php-fpm-oci8/blob/master/Dockerfile
which seems to create a p-fpm-oci8 docker image
the "wget" for
wget -qO- https://raw.githubusercontent.com/caffeinalab/php-fpm-oci8/master/oracle/instantclient-basic-linux.x64-12.2.0.1.0.zip | bsdtar -xvf- -C /usr/local &&
wget -qO- https://raw.githubusercontent.com/caffeinalab/php-fpm-oci8/master/oracle/instantclient-sdk-linux.x64-12.2.0.1.0.zip | bsdtar -xvf- -C /usr/local &&
wget -qO- https://raw.githubusercontent.com/caffeinalab/php-fpm-oci8/master/oracle/instantclient-sqlplus-linux.x64-12.2.0.1.0.zip | bsdtar -xvf- -C /usr/local && \
can be dropped when you place downloaded instant client files into local host dir
/usr/local
and extract them - resulting in
/usr/local/instantcient_12_2
or 18, 19c equivalents
the 4 "ln" commands have to be adjusted to reflect the local host instantclient dir
the tnsnames.ora for instantclient is available from host by VOLUME command
-------------FINAL SOLUTION------------(it was not network related, I had done a couple of changes to the files, and also tried a different database, all at the same time, so it made me think that it was the different database what fixed the issue)
After many trial and errors, I came up with a Dockerfile that creates the correct configuration of files and connects without any issues to the database:
--Dockerfile: (to build php-fpm 7.4 using devilbox image)
Final solution:
I modified the Dockerfile file of the php-fpm to add new instant client files and not the one that were provided by the original file. I was not able to make it work with them. I have tried a few times rebuilding the image (docker-compose up --build) and this is the file that does the trick:
FROM devilbox/php-fpm:7.4-work
ADD instantclient.conf /etc/ld.so.conf.d/
WORKDIR /opt
RUN wget https://download.oracle.com/otn_software/linux/instantclient/19800/instantclient-sdk-linux.x64-19.8.0.0.0dbru.zip
RUN wget https://download.oracle.com/otn_software/linux/instantclient/19800/instantclient-sqlplus-linux.x64-19.8.0.0.0dbru.zip
RUN wget https://download.oracle.com/otn_software/linux/instantclient/19800/instantclient-basic-linux.x64-19.8.0.0.0dbru.zip
RUN unzip instantclient-sdk-linux.x64-19.8.0.0.0dbru.zip
RUN unzip instantclient-sqlplus-linux.x64-19.8.0.0.0dbru.zip
RUN unzip instantclient-basic-linux.x64-19.8.0.0.0dbru.zip
RUN mv instantclient_19_8 instantclient
ADD tnsnames.ora /opt/instantclient/network/admin
RUN ldconfig -v
CMD ["php-fpm"]
expose 9000
That's why I have suggested to use tnsping - unfortunaly it is not included in any of the instant client files which is a pity - so you have to pick it up from regular client with matching OS, bitsize and Oracle release. As workaround you could place SQL*Plus package files into container and try to connect with a foo user like
sqlplus foo/foo#\<ip>:\<port>/\<dbname>
which should generate an error - if
user/password not matching - ORA-1017 i.e. DB & listener running
listener running - ORA-1034 i.e. DB down
listener down (no return, or TNS-Errors)
I got it!. It was a firewall issue. I launched a tcpdump capture
session and there was nothing wrong with php-fpm, oci8 and
instantclient libraries. The traffic was initiated but there was no
response from the database. I made it work against a different
database where this box has no firewall issues.
I now will try rebuilding the docker image so I can see what I have to
manually add if any.
That was incorrect (the firewall as the origin of the problem). Rebuilding the docker file showed me where I had it wrong. See original question for solution.
I am developping a website which I want to host inside a php-apache docker container.
I use the following command to run the container:
docker run -dit --restart unless-stopped --name my_www -p 8080:80 -v /path/to/repo:/var/www/html/ php:7.4-apache
Since I bind the repository containing the code as a volume to the container, I expect the website to "update live" when I change the code locally. I had this right behaviour last time I tried but I am now unable to get it back.
When I check the website locally at 127.0.0.1 everything is ok and changes are taken into account normaly, but they do not propagate into the docker container...
For some reason, the files in the docker are stuck to an old version of the code, an old "stat" of the repository...
Any ideas how I can manage to fix this and preview changes live ?
Credits to #Don't Panic for helping to debug.
The browser was caching everything so I couldn't see changes live.
The solution was to enable the "expires" apache module inside the docker container:
$ docker exec -it <container_id> bash
root#<container_id>:# a2enmod expires
root#<container_id>:# exit
$ docker restart my_www
Et voilà :)
I'm trying to run a ready PHP app (a copy of existing site - just want to run it locally) in Docker.
I tried some from that: https://semaphoreci.com/community/tutorials/dockerizing-a-php-application but no luck. One friend told me that I should also have a server for that which confused me a bit. I know PHP have self-hosting capabilities (not recommended for production tho, but I need it just for testing purposes).
I also tried docker run -it --rm --name my-running-script -p 8080:8080 -v /Users/jans/Developer/sfolder:/usr/src/myapp -w /usr/src/myapp php:5.6 bash and run it from bash with php index.php (and yes - I used ls earlier to see if there are any files in there and they are), but nothing happens and localhost:8080 is not available.
I'm also trying to use https://hub.docker.com/r/1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5/ but this is really complicated to me and can't do anything at all with it.
Anyone with experience how to run PHP app will be more than welcome.
I'm following a docker web application setup tutorial from here. As described in the docker-compose.yml file the MySQL container is linked to the app and it is accessible via both index.php and phpMyAdmin. No problem so far.
When I opened an interactive shell for my application using docker exec -it container-id bash and tried to access the MySQL service but I couldn't. What I'm I missing here?
Edit1: When I type MySQL, I get bash: mysql: command not found.
Edit2: Output of docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1643f0ba5637 dockertutorial_php "docker-php-entryp..." 9 seconds ago Up 6 seconds 9000/tcp dockertutorial_php_1
610f2c8bf4c4 phpmyadmin/phpmyadmin "/run.sh phpmyadmin" 9 seconds ago Up 6 seconds 0.0.0.0:8080->80/tcp dockertutorial_phpmyadmin_1
29c552da473b mysql:latest "docker-entrypoint..." 10 seconds ago Up 8 seconds 3306/tcp dockertutorial_mysql_1
Edit3: Perhaps I should have started with this. I apologise for all the confusion caused/would cause (Especially to #Jay Blanchard & #mkasberg). I want to run a bash script inside the nginx container which creates a MySQL database. It works if I have installed MySQL in the nginx container but not if it is a separate container. Is it possible to achieve with the current approach? If not how should I correct it?
mysql: command not found means that the mysql client binary is not available in whichever container you're logged in to. I suspect you're running docker exec on a container other than the MySQL one. The binary would be there in the MySQL container. While those other containers can connect do MySQL, they don't have the MySQL command line application available (to keep image size small).
Make sure you're connecting to the MySQL container with your docker exec command and it should work. In fact, docker-compose provides a way for you to do this. With your services running (after doing docker-compose up), try this:
$ docker-compose exec mysql /bin/bash
That should get you to a bash prompt in the mysql container. Before, you were getting to a bash prompt in the nginx container. Which can't run mysql on the command line.
I have encapsulated pdftk (PDF tool kit) as program that can be run inside of a fedora docker image. This allows me to run pdftk on a newer AWS AMI image that does not support pdftk. When replacing pdftk in our PHP program with the docker run command, it works great when running the PHP program from the command line, but when running it as a cron job or as a mailbox command, docker will not run. I have made the cron and mailbox users part of the docker group, checked permissions and paths, but still no joy.
The exec PHP command looks like:
$command = 'docker run -i -t --privileged -v /var/www/mbx/forms/inbox:/workdir -w /workdir/ brnlab/aultman-pdftk ./'.basename($files[$i]).' burst output ./pg_%03d.pdf';
Oddly the return on the $command when running this as a cron or mailbox command is blank, so I am not sure if there is an error or not. It does not appear to hang up. Any ideas on the best way to diagnose the issue further?