I have created a simple tech stack using Docker. PHP 7.2 on CentOS.
Below is the docker file
FROM centos:7
# Install Apache
RUN yum -y update
RUN yum -y install httpd httpd-tools
# Install EPEL Repo
RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
&& rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# Install PHP
RUN yum -y install php72w php72w-bcmath php72w-cli php72w-common php72w-gd php72w-intl php72w-ldap php72w-mbstring
php72w-mysql php72w-pear php72w-soap php72w-xml php72w-xmlrpc
# Update Apache Configuration
RUN sed -E -i -e '/<Directory "/var/www/html">/,/</Directory>/s/AllowOverride None/AllowOverride All/' /etc/httpd/conf/httpd.conf
RUN sed -E -i -e 's/DirectoryIndex (.*)$/DirectoryIndex index.php 1/g' /etc/httpd/conf/httpd.conf
EXPOSE 80
# Start Apache
CMD ["/usr/sbin/httpd","-D","FOREGROUND"]
Below is the docker-compose.yml
version: '3.2'
services:
centos-php-apache:
build:
context: ./
ports:
- "8080:80"
volumes:
- ./code:/var/www/html
All is now running fine. After few days, I decided to update the following –
(i) Update “dockerfile” by adding another php-module or php-extension
(ii) Update the docker compose.yml by adding another service (say) “mariadb”.
I would like to do this update, without effecting or deleting any files from the previous setup. In fact, this is a common scenario, where developers may need additional extensions or service in the future – without redoing everything right from the beginning.
Should I directly edit the "dockerfile" and add the php extension and edit the docker-compose.yml file and add the service as usual and then run the docker-compose up command. Of course before running the "up" command, I will first bring it down using the docker-compose down command.
Can anyone throw some light, on how I can accomplish this.
2
Answers
It would be best if you used
docker-compose up --build centos-php-apache
instead ofdocker-compose up
. And you do not want to worry about data. They are persistent with your volume map. Also, make sure to use another volume map for your mariadb data.I am adding a dummy setup, together with the contents of the files:
Assuming that you just performed the change in the web-app/Dockerfile, you have a couple of options:
Option A:
You rebuild one specific image, while the current containers are not affected:
When you are comfortable with the image that you built, redeploy the containers that suffered image changes(note that if you run docker-compose up, only the web-app is redeployed):
Option B:
If your confident with the changes that you performed on the Dockerfile, go for the one-liner with the
--build
option: