Comments (16)
@booyaa Thanks!! I did that, and also included regular mysql and pdo, and also added a RUN for enabling mod_rewrite on apache, which we were previously doing by an exec command.
For anyone who comes upon this issue, be it known that the following Dockerfile works as expected:
FROM php:5.4-apache
RUN docker-php-ext-install mysql mysqli pdo pdo_mysql
RUN cp /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
I'll defer to ya'all's judgement in removing all the extensions, and I thank you very much for the magic install extensions script.
I have 2 questions to finish up this issue and have our company's dev workflow back on track:
First, should I have 2 separate RUN commands like that or should I do that && thing?
Second, would it make more sense to include the Dockerfile in our code repository, and so have devs clone the repository, then build the Dockerfile, then run the containers, or does it make more sense to store the new image on docker hub and have them download it by running the containers?
from php.
Speaking in an unofficial capacity I kinda understand why Docker don't want to put anything extra into an image, because there will be another person who wants postgres and doesn't need the overhead of a mysql bindings.
I haven't had a chance to test, but this should be easily remedied by creating a custom php build (basing this off the wordpress image which builds off php).
Dockerfile
FROM php:5.4-apache
RUN docker-php-ext-install mysqli
Then you can do docker build -t php-mysql:5.4-apache .
and issue docker run -d -p 80:80 --name kcity-web -v "$(pwd)":/var/www/html --link kcity-mysql:mysql php-mysql:5.4-apache
The bonus being you could even include a COPY of your website into the container, to simplify that docker run
.
As a side note, have you looked at using docker-compose? It's really handy, once you go beyond a single docker run and in turn each command has a dependency on the previous.
from php.
@yosifkit right on with that setup with PDO!!! Thanks a lot! It saved my life tonight!
RUN docker-php-ext-install mysql mysqli pdo pdo_mysql
from php.
@AwokeKnowing I'd recommend RUN a2enmod rewrite
instead. Those files under mods-enabled
are normally symlinks, not copies.
from php.
@booyaa 👍
from php.
As for the complicated &&
stuff in the RUN
statements, I believe that's mostly to keep the number of layers in the base images small. Since your image will likely not be further extended, I see no problem with separate RUN
statements.
from php.
@md5 Ok, yeah I'll try a2enmod. can't remember why we had copy. The "few layers" makes sense. I guess the next things to do are put the image in docker hub and figure out how "compose" works to make it all seemless.
from php.
I would suggest putting the Dockerfile in your git repo and have devs build it themselves. It helps them understand the dependencies that get installed (and they can easily submit changes to add new deps). You do have to teach them to pull the base image every once in a while and rebuild so that security fixes get propagated. My opinion is that there are only a few times you want to pass an image around: base images (like official images provide), and when going from QA to production (ie QA servers build the image and test it, then that image can be deployed to production). It would require adding a COPY to your Dockerfile (but still bind mount with -v
for developers for live code changes).
FROM php:5.4-apache
RUN docker-php-ext-install mysql mysqli pdo pdo_mysql
RUN cp /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
COPY . /var/www/html
from php.
You do have to teach them to pull the base image every once in a while
Or use docker build --pull .
, which should perform a pull before building
from php.
@thaJeztah great tip! I hadn't seen that before.
from php.
It was added at some point but not much exposure :)
from php.
It helps them understand the dependencies that get installed
Thank you for this insight. I agree.
Regarding:
adding a COPY to your Dockerfile (but still bind mount with -v for developers for live code changes).
How does it work to copy those files into your web document root and also mount your local folder into the same location?
from php.
How does it work to copy those files into your web document root and also mount your local folder into the same location?
A bind-mounted volume is mounted "over" the files in the image; basically, they "mask" / "hide" the underlying files in the image. The container then uses the files that are in the volume, in stead of the container itself, which allows you to make changes to those files without going "inside" the container.
Once the changes are complete, rebuild the image (which will ADD/COPY the most recent files into the image) and ship it.
from php.
It allows you to use the same Dockerfile for QA and production, skip the -v
and all the files are ready to go.
from php.
Thanks everyone for your help and insight!
from php.
Spent some time trying to install the mysql PDO extention from the base image yesterday. Wish I had stumbled on that sooner.
Btw, yet another way to setup rewrite:
RUN ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
from php.
Related Issues (20)
- [php:8.3-apache] HIGH Vulnerability on apache <=2.4.57 HOT 4
- curl error on php:8.2-apache (bookworm) HOT 1
- Add Support for shmop HOT 1
- Remove archive php.tar.xz from final images HOT 1
- php8.2.15 removed ftp extension HOT 12
- Connectivity issue after php:8.0-fpm HOT 13
- Error during build prod.Dockerfile
- Changes on httpd without reload HOT 6
- Configuring PHP directives without custom images HOT 5
- Can't install php7.4-sybase package on php:7.4-apache-bullseye HOT 3
- iconv ASCII//TRANSLIT invalid argument HOT 2
- Php
- Add mlocati/docker-php-extension-installer to base image HOT 1
- Update apache 2.4.57-2 to 2.4.58-1 HOT 4
- ext-sockets won't compile in official Docker image 8.3.3-fpm-alpine3.19 HOT 2
- Interpreter does not resolve builtin functions when provide nonexistente file to opcache.preload option HOT 1
- Can't rename the php.ini-development HOT 2
- Podman php:cli with xdebug: Unable to debug php:cli in Visual Studio Code when using podman (Works in Docker) HOT 10
- Bundled curl version is causing segfault HOT 1
- Update libxml in php:7.3-apache to version 2.9.14 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php.