Giter VIP home page Giter VIP logo

Comments (16)

AwokeKnowing avatar AwokeKnowing commented on May 18, 2024 7

@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.

booyaa avatar booyaa commented on May 18, 2024 6

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.

marcellodesales avatar marcellodesales commented on May 18, 2024 5

@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.

md5 avatar md5 commented on May 18, 2024 1

@AwokeKnowing I'd recommend RUN a2enmod rewrite instead. Those files under mods-enabled are normally symlinks, not copies.

from php.

md5 avatar md5 commented on May 18, 2024

@booyaa 👍

from php.

md5 avatar md5 commented on May 18, 2024

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.

AwokeKnowing avatar AwokeKnowing commented on May 18, 2024

@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.

yosifkit avatar yosifkit commented on May 18, 2024

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.

thaJeztah avatar thaJeztah commented on May 18, 2024

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.

md5 avatar md5 commented on May 18, 2024

@thaJeztah great tip! I hadn't seen that before.

from php.

thaJeztah avatar thaJeztah commented on May 18, 2024

It was added at some point but not much exposure :)

from php.

AwokeKnowing avatar AwokeKnowing commented on May 18, 2024

@yosifkit

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.

thaJeztah avatar thaJeztah commented on May 18, 2024

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.

yosifkit avatar yosifkit commented on May 18, 2024

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.

AwokeKnowing avatar AwokeKnowing commented on May 18, 2024

Thanks everyone for your help and insight!

from php.

Magnitus- avatar Magnitus- commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.