Hi guys, I just downloaded the image PHP5.6-apache, but I need to activate the module "mod_rewirte" what I did to activate it, was going to "bash" and run "a2enmod rewrite" and it worked. I did a "commit" of this container but the problem is that now I run "my new image" and it seems that it is not running the "CMD [" apache2-foreground "]" command when I create a new container
Your best solution is going to create a new Dockerfile from this one, something like this:
FROM php:5.6-apache
RUN a2enmod rewrite
Combine that with automated builds (https://docs.docker.com/docker-hub/builds/) and repository links (https://docs.docker.com/docker-hub/builds/#repository-links) and it's reasonably easy to have an up-to-date image built FROM this one with the rewrite module enabled. :+1:
I had thought of that, but I wanted to know if there is a better way, or "best practices" to do this without creating a new "Dockerfile".
Thank you for guiding me.
:whale:file is your friend, don't be mean to it, it's just innocent ASCII
Thanks @iamsortiz
You welcome @bufface.
I also rejected the idea at first, and sincerely laughed at it, but you'll end up adding some more apache mods or libraries (imagemagick, etc) and having that Dockerfile will be useful for upgrading your base apache container. I recommend you putting that base apache in a public repo, it could be useful for someone or just as "personal marketing" to show up you are using Docker and creating your own containers.
Bear in mind that this could be a first step into a "continuous integration" or "continuous delivery" workflow, where you have multiple containers you'd like to test and deploy together (just for fun, just for the coolness of that, or just for the "personal marketing").
In my workplace the codebase it's getting more complex everyday so any automation is welcome.
When you want to use multiple commands you use /bin/bash -c. Thus said, I did it with the following command. (I didn't want to create a docker file for just one command either)
docker run -v myhtml:/var/www/html -p 8000:80 php:5.6-apache /bin/bash -c 'a2enmod rewrite; apache2-foreground'
Thanks @silgon
I would add:
docker run -d -v $PWD:/var/www/html --name php_apache -p 8000:80 php:5.6-apache /bin/bash -c 'a2enmod rewrite; apache2-foreground'
If anyone is interested here you got a Gist with some convenience bash scripts around this idea:
Extract of the Gist:
PHP_VERSION='5.6'
CONTAINER_NAME='php_apache'
function php_apache-run() {
docker run -d -v $PWD:/var/www/html --name $CONTAINER_NAME -p 8000:80 php:$PHP_VERSION-apache /bin/bash -c 'a2enmod rewrite; apache2-foreground'
}
alias php_apache-start="docker start $CONTAINER_NAME"
alias php_apache-stop="docker stop $CONTAINER_NAME"
alias php_apache-kill="docker rm -f $CONTAINER_NAME"
alias php_apache-logs="docker logs -t $CONTAINER_NAME"
alias php_apache-logs_live="docker logs -t -f $CONTAINER_NAME"
edited bug: alias php_apache-run="docker run -d -v $PWD:/var/www/html --name $CONTAINER_NAME -p 8000:80 php:$PHP_VERSION-apache /bin/bash -c 'a2enmod rewrite; apache2-foreground'"
In the Gist there are 2 more functions:
@bufface if your are interested in using the container with the volume of your actual folder, probably the script way is better, because in the end even with Dockerfile you'll have to write that long bash line to run the container with the port, volume, name, etc.
Even if u use docker-compose, where you can define the port and the volume, you'll have to hack a bit to get the right path used, because it uses absolute path's, relative to home folder, or relative to docker-compose.yml, so if you want your actual folder to be used you'll have to use and set environmental or bash variables, and again you'll end up writing messy bash or doing again some bash alias/function.
So I retract in my previous opinion about the Dockerfile, but I suggest using some form of bash alias/function to encapsulate it
Thanks @iamsortiz. Very useful your Gist.
Most helpful comment
Your best solution is going to create a new
Dockerfilefrom this one, something like this:Combine that with automated builds (https://docs.docker.com/docker-hub/builds/) and repository links (https://docs.docker.com/docker-hub/builds/#repository-links) and it's reasonably easy to have an up-to-date image built
FROMthis one with therewritemodule enabled. :+1: