<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Richard Spindler</title>
    <description>The latest articles on DEV Community by Richard Spindler (@oracle2025).</description>
    <link>https://dev.to/oracle2025</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F81798%2F1770aab2-8387-4e06-9e78-49bf5f3cd203.jpeg</url>
      <title>DEV Community: Richard Spindler</title>
      <link>https://dev.to/oracle2025</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/oracle2025"/>
    <language>en</language>
    <item>
      <title>Get a Legacy PHP (5.3) application running in Docker</title>
      <dc:creator>Richard Spindler</dc:creator>
      <pubDate>Wed, 27 Apr 2022 09:24:00 +0000</pubDate>
      <link>https://dev.to/oracle2025/get-a-legacy-php-53-application-running-in-docker-1cb2</link>
      <guid>https://dev.to/oracle2025/get-a-legacy-php-53-application-running-in-docker-1cb2</guid>
      <description>&lt;p&gt;In this article I use docker-compose to create a MySQL+PHP environment to run a Legacy application.&lt;/p&gt;

&lt;p&gt;A Legacy application is an app that needs an old and outdated version of PHP to work.&lt;/p&gt;

&lt;p&gt;Official images for PHP are available from Docker hub here: &lt;a href="https://hub.docker.com/_/php/"&gt;https://hub.docker.com/_/php/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I use the oldest image available from there:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;php:5.3.29-apache&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can download the image right away with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker pull php:5.3.29-apache
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the sake of example I provide a small snippet of PHP code, that only works with older PHP versions.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;index.php&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="nv"&gt;$conn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;mysql_connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"localhost"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"saxud3sldnb"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;mysql_select_db&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"application_db"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;mysql_close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$conn&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;mysql_connect&lt;/code&gt; is no longer available in recent PHP versions&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To keep track of the docker configurations and settings create a &lt;code&gt;docker-compose.yml&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Because then I can commit the &lt;code&gt;docker-compose.yml&lt;/code&gt; into the repository and keep track of the steps required to set up the environment.&lt;/p&gt;

&lt;p&gt;The following file is the starting version:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker-compose.yml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3.7'
services:
  legacy-php:
    image: php:5.3.29-apache
    volumes:
    - .:/var/www/html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then try to run it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker-compose run -T legacy-php php /var/www/html/index.php
Creating example-legacy-php-app_legacy-php_run ... done

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /var/www/html/index.php on line 2

Warning: mysql_select_db(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /var/www/html/index.php on line 3

Warning: mysql_select_db(): A link to the server could not be established in /var/www/html/index.php on line 3

Warning: mysql_close() expects parameter 1 to be resource, boolean given in /var/www/html/index.php on line 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are some errors, because the MySQL server is not yet set up and connected.&lt;/p&gt;

&lt;p&gt;This is the next step.&lt;/p&gt;

&lt;p&gt;MySQL Docker images are available here:&lt;br&gt;
&lt;a href="https://hub.docker.com/r/mysql/mysql-server/"&gt;https://hub.docker.com/r/mysql/mysql-server/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I am using version &lt;code&gt;5.7.37&lt;/code&gt; in this guide:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker pull mysql/mysql-server:5.7.37
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's add the image to the docker-compose.yml file:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker-compose.yml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3.7'
services:
  mysql:
    image: mysql/mysql-server:5.7.37
    environment:
     MYSQL_DATABASE: application_db
     MYSQL_USER: user
     MYSQL_PASSWORD: saxud3sldnb
    restart: always
  legacy-php:
    depends_on:
     - mysql
    image: php:5.3.29-apache
    volumes:
    - .:/var/www/html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The PHP example script requires a small change:&lt;/p&gt;

&lt;p&gt;Use hostname "mysql" instead of "localhost".&lt;/p&gt;

&lt;p&gt;&lt;code&gt;index.php&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="nv"&gt;$conn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;mysql_connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"mysql"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"saxud3sldnb"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nb"&gt;mysql_select_db&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"application_db"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;mysql_close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$conn&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run this with the same commandline as above, and get an empty output.&lt;/p&gt;

&lt;p&gt;The script does not do much yet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker-compose run -T legacy-php php /var/www/html/index.php  
Creating example-legacy-php-app_legacy-php_run ... done
$ 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So lets query the database for existing users.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;index.php&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="nv"&gt;$conn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;mysql_connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"mysql"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"saxud3sldnb"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nb"&gt;mysql_select_db&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"application_db"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;mysql_query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"SELECT * FROM `users`"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;$result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Error: "&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nb"&gt;mysql_error&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$row&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;mysql_fetch_assoc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$result&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;foreach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$row&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$key&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="s2"&gt;": "&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="s2"&gt;", "&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;mysql_close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$conn&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running this example gives an error message, because the database is empty, and the table cannot be found.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker-compose run -T legacy-php php /var/www/html/index.php 
Creating example-legacy-php-app_legacy-php_run ... done
Error: Table 'application_db.users' doesn't exist%
$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's initializing the database with a simple example, to &lt;br&gt;
get the code working.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;init.sql&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE `users`(
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(80) NOT NULL DEFAULT '',
  `password` varchar(40) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`)
);
INSERT INTO `users`(`name`,`password`) VALUES ('admin', MD5('passw0rd'));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The sql script above creates an initial table, and an admin user, with a md5 encoded password.&lt;/p&gt;

&lt;p&gt;Using pure md5 is a bad algorithm for passwords, it is used here just for the example.&lt;/p&gt;

&lt;p&gt;The MySQL docker images have a script to initialize the database, lets add &lt;code&gt;init.sql&lt;/code&gt; to the correct place:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker-compose.yml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3.7'
services:
  mysql:
    image: mysql/mysql-server:5.7.37
    environment:
     MYSQL_DATABASE: application_db
     MYSQL_USER: user
     MYSQL_PASSWORD: saxud3sldnb
    restart: always
    volumes:
     - ./init.sql:/docker-entrypoint-initdb.d/init.sql
  legacy-php:
    depends_on:
     - mysql
    image: php:5.3.29-apache
    volumes:
     - .:/var/www/html
    ports:
     - "8002:80"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Port 80 is forwarded to the local machine, test the
application at &lt;a href="http://localhost:8002"&gt;http://localhost:8002&lt;/a&gt; from a webbrowser.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Restart the MySQL container to run the new init script.&lt;/p&gt;

&lt;p&gt;Then run the example again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker-compose stop
Stopping example-legacy-php-app_mysql_1 ... done
$ docker-compose run -T legacy-php php /var/www/html/index.php 
Creating example-legacy-php-app_legacy-php_run ... done
id: 1, name: admin, password: bed128365216c019988915ed3add75fb%
$ 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And this concludes the article.&lt;/p&gt;

&lt;p&gt;What was done:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A Docker container to run PHP 5 specific code&lt;/li&gt;
&lt;li&gt;A MySQL container connected to the PHP container&lt;/li&gt;
&lt;li&gt;The database is initialized and ready for use.&lt;/li&gt;
&lt;li&gt;Open the application from a webbrowser&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This article was extracted from a small eBook I wrote and published for Free as a PDF here: &lt;a href="https://php5to8.tk"&gt;https://php5to8.tk&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Enjoy 😸&lt;/p&gt;

</description>
      <category>php</category>
      <category>mysql</category>
      <category>docker</category>
      <category>legacycode</category>
    </item>
    <item>
      <title>Howto use Docker Agent in a Jenkinsfile Matrix Build</title>
      <dc:creator>Richard Spindler</dc:creator>
      <pubDate>Tue, 06 Jul 2021 07:04:35 +0000</pubDate>
      <link>https://dev.to/oracle2025/howto-use-docker-agent-in-a-jenkinsfile-matrix-build-11m0</link>
      <guid>https://dev.to/oracle2025/howto-use-docker-agent-in-a-jenkinsfile-matrix-build-11m0</guid>
      <description>&lt;p&gt;There is one simple tutorial that I was looking for on the web, and I could not find it.&lt;/p&gt;

&lt;p&gt;So I wrote it myself.&lt;/p&gt;

&lt;p&gt;Jenkins has matrix builds, and Jenkins has agent docker for builds inside a docker image.&lt;/p&gt;

&lt;p&gt;Combined, these features make it easy to test a project with multiple versions of PHP for example.&lt;/p&gt;

&lt;p&gt;So here is the simple example I came up with: Put this in your Jenkinsfile and you are done.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
    agent none
    stages {
        stage('Test') {
            matrix {
                agent {
                    docker { image "${DOCKER_IMAGE}" }
                }
                axes {
                    axis {
                        name 'DOCKER_IMAGE'
                        values 'php:5.3', 'php:5.6'
                    }
                }
                stages {
                    stage('Test') {
                        steps {
                            sh 'php --version'
                        }
                    }
                }
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please let me know if it helps you 😊&lt;/p&gt;

&lt;h2&gt;
  
  
  Learning more
&lt;/h2&gt;

&lt;p&gt;Testing your software in different environments is a best practice for software engineering.&lt;/p&gt;

&lt;p&gt;If you like this article: I am writing a book about best practices for legacy code projects:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://softwareteambook.tk/"&gt;Leading a Legacy Software Team&lt;/a&gt;&lt;/p&gt;

</description>
      <category>jenkins</category>
      <category>docker</category>
      <category>php</category>
    </item>
    <item>
      <title>How to keep a Dockerfile updated with Dependabot</title>
      <dc:creator>Richard Spindler</dc:creator>
      <pubDate>Wed, 16 Jun 2021 09:45:37 +0000</pubDate>
      <link>https://dev.to/oracle2025/how-to-keep-a-dockerfile-updated-with-dependabot-1mdn</link>
      <guid>https://dev.to/oracle2025/how-to-keep-a-dockerfile-updated-with-dependabot-1mdn</guid>
      <description>&lt;p&gt;&lt;em&gt;Dependabot&lt;/em&gt; used to be a separate service that scanned your github repository for outdated dependencies in 3rd party packages and libraries.&lt;/p&gt;

&lt;p&gt;This service was acquired by Github and is now integrated into the platform.&lt;/p&gt;

&lt;p&gt;It is a free service, and a great way to keep your projects dependencies up to date.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Dependabot&lt;/em&gt; will automatically create a pull request to your project to bump any outdated dependencies to the latest version.&lt;/p&gt;

&lt;p&gt;As an example project I am using a simple "Hello World" style PHP script that runs in the standard PHP Docker image. And &lt;em&gt;Dependabot&lt;/em&gt; will bring the outdated PHP version up to date with.&lt;/p&gt;

&lt;p&gt;To verify that the application is compatible with the updated version of PHP a Github actions workflow will run the code with the &lt;code&gt;Dockerfile&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So here is what you will learn:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a &lt;code&gt;Dockerfile&lt;/code&gt; and &lt;code&gt;hello.php&lt;/code&gt; as the application&lt;/li&gt;
&lt;li&gt;Create a Github Actions workflow to run the above code in Docker&lt;/li&gt;
&lt;li&gt;Enable &lt;em&gt;Dependabot&lt;/em&gt; for Docker&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Dockerfile
&lt;/h2&gt;

&lt;p&gt;This is the simplest &lt;code&gt;Dockerfile&lt;/code&gt; for running a PHP script. The current stable version of PHP is &lt;code&gt;8.0.7&lt;/code&gt; but I am using a slightly outdated version number. I want to see &lt;em&gt;Dependabot&lt;/em&gt; taking action on this outdated version.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

FROM php:8.0.0


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Note: Rather than using a specific version I could use the Docker tag &lt;code&gt;latest&lt;/code&gt; to always have the latest version. But this is considered a bad practice.&lt;/p&gt;

&lt;p&gt;Before upgrading to the latest version of a dependency, you must run your applications tests.&lt;/p&gt;

&lt;p&gt;Without a specific version in the &lt;code&gt;Dockerfile&lt;/code&gt; you cannot run an automated test suite before the upgrade.&lt;/p&gt;

&lt;h2&gt;
  
  
  hello.php
&lt;/h2&gt;

&lt;p&gt;This Hello World will not actually print the string "Hello World", but instead the current PHP version number. Therefore the logs of the actions workflow show if the PHP version has been updated correctly and that the correct &lt;code&gt;Dockerfile&lt;/code&gt; was used.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;?
echo phpversion();
?&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  .github/workflows/php.yml
&lt;/h2&gt;

&lt;p&gt;This is a very basic actions workflow that runs on the &lt;em&gt;main&lt;/em&gt; branch and also on any pull requests that are made for the &lt;em&gt;main&lt;/em&gt; branch.&lt;/p&gt;

&lt;p&gt;Github recently updated the default branch name from &lt;em&gt;master&lt;/em&gt; to using &lt;em&gt;main&lt;/em&gt;. So if you have an older repository, you must change this example to work with the old convention.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

name: PHP CI
on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Build docker images
      run: docker build -t local - &amp;lt; Dockerfile
    - name: Run tests
      run: docker run -t -v $PWD:/srv -w/srv local php hello.php


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This builds the &lt;code&gt;Dockerfile&lt;/code&gt; and runs the code in &lt;code&gt;hello.php&lt;/code&gt; inside that image.&lt;/p&gt;

&lt;h2&gt;
  
  
  .github/dependabot.yml
&lt;/h2&gt;

&lt;p&gt;To enable &lt;em&gt;Dependabot&lt;/em&gt; you must go to "Insights" on your repository main page.&lt;/p&gt;

&lt;p&gt;The setting for &lt;em&gt;Dependabot&lt;/em&gt; is hidden under "Dependency Graph":&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqwq41huazm7wvxmnduwk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqwq41huazm7wvxmnduwk.png" alt="Screenshot of Dependabot Settings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can use the default configuration file that is suggested by Github. Just add "docker" to "package-ecosystem", &lt;em&gt;Dependabot&lt;/em&gt; will find your &lt;code&gt;Dockerfile&lt;/code&gt; automatically.&lt;/p&gt;

&lt;p&gt;For me the &lt;code&gt;dependabot.yml&lt;/code&gt; looks like this:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&lt;p&gt;version: 2&lt;br&gt;
updates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;package-ecosystem: "docker"
directory: "/"
schedule:
  interval: "daily"&lt;/li&gt;
&lt;/ul&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Waiting for a pull request&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;Now &lt;em&gt;Dependabot&lt;/em&gt; is set up and ready to go. It will check your &lt;code&gt;Dockerfile&lt;/code&gt; daily, and creates a pull request to upgrade to the latest stable release of PHP.&lt;/p&gt;

&lt;p&gt;And the pull request is verified by the Github actions workflow that I created above.&lt;/p&gt;

&lt;p&gt;For me the diff from the commit by the Dependabot looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc1zxzxognfchl5wtflya.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc1zxzxognfchl5wtflya.png" alt="Screenshot of commit for Dockerfile upgrade"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Learning more
&lt;/h2&gt;

&lt;p&gt;Keeping your dependencies up to date is a best practice for software engineering.&lt;/p&gt;

&lt;p&gt;If you like this article: I am writing a book about best practices for legacy code projects:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://softwareteambook.tk/" rel="noopener noreferrer"&gt;Leading a Legacy Software Team&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>github</category>
      <category>php</category>
    </item>
  </channel>
</rss>
