How to update docker containers
Learn the easy way how to update docker containers. I show how I upgraded this site to the latest WordPress container.
Read on for my walk through on updating docker containers.
Update Docker Containers
I was aware I had been running this site for around three months but I hadn't updated the underlying containers. This wasn't a problem but it did mean my containers had stood still missing security updates amongst other things.
Maybe like you, I wasn't sure how easy it is to update containers. Here you can see how old my docker images were.
I wasn't clear what the workflow was to update the containers and I was a bit reluctant to mess around with something that was working ok. I knew PHP was out of date in my WordPress container running 5.6.17, where the latest included version was 5.6.20. What else was I missing from using an out of date container?
Updating WordPress Container
WordPress 4.5 was released recently and I wanted to know the proper way to upgrade WordPress via Docker.
I thought if I downloaded the latest WordPress image, it would come with an upgrade to 4.5 automatically somehow. I was looking at deleting the container, letting it be recreated with the new image. None of that was needed.
Docker Compose Pull
After a bit of testing I came across this gem, which if your not familiar with is a good find:
The documentation doesn't exactly go to town with explaining this function - "Pulls service images". Basically, it will check what images you are using via your docker-compose.yml and if their not up-to-date, they will be downloaded, assuming you haven't specified a particular image.
This updated the images accordingly
Recreating Docker Containers
Now if you run 'docker-compose up -d', the corresponding containers are recreated automatically:
With data stored separately (see my setup guide), in my case in a data only container, I knew this shouldn't disrupt the service.
I still had upgrade WordPress manually, this won't happen automatically. Using the same WordPress image on a new container with no existing data it will go straight to version 4.5 by the way.
Using WordPress's built-in update mechanism by clicking the 'Update Now' button kicked it off:
The WordPress database then needs updating:
Recreating containers was such a novelty for me at the start , I wanted to confirm the containers were truly being upgraded. On my WordPress container I installed a plugin called WordPress phpinfo(). This showed behind the scenes, the container had been upgraded, using the PHP version as an example.
Update Docker Containers Wrap Up
I hope this was of interest and look out for future Docker posts.