Skip to content

Quickly patching a Docker image

Hugo Denizart edited this page Jan 3, 2024 · 3 revisions

How to quickly edit a Docker image (eg. quick osu-web changes)

  1. Pull the desired base image to edit (based on tag or SHA)
docker pull pppy/osu-web:3431d70972d6124081b103da6e42ced98a003607
  1. Create a container
docker run --entrypoint /bin/bash --user root -it pppy/osu-web:3431d70972d6124081b103da6e42ced98a003607 
  1. Make desired edits
root@7f056be66b87:/app# apt-get update && apt-get install nano
Hit:1 http://deb.debian.org/debian bullseye InRelease
Get:2 http://deb.debian.org/debian-security bullseye-security InRelease [48.4 kB]
Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
Hit:4 https://packages.sury.org/php bullseye InRelease    
Get:5 http://deb.debian.org/debian-security bullseye-security/main amd64 Packages [264 kB]
Fetched 357 kB in 5s (66.7 kB/s) 
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
  hunspell
The following NEW packages will be installed:
  nano
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 657 kB of archives.
After this operation, 2591 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bullseye/main amd64 nano amd64 5.4-2+deb11u2 [657 kB]
Fetched 657 kB in 0s (8623 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package nano.
(Reading database ... 12481 files and directories currently installed.)
Preparing to unpack .../nano_5.4-2+deb11u2_amd64.deb ...
Unpacking nano (5.4-2+deb11u2) ...
Setting up nano (5.4-2+deb11u2) ...
update-alternatives: using /bin/nano to provide /usr/bin/editor (editor) in auto mode
update-alternatives: using /bin/nano to provide /usr/bin/pico (pico) in auto mode
root@7f056be66b87:/app# nano LICENCE 
root@7f056be66b87:/app# exit
exit
  1. Commit and push
# In the case of osu-web, we have to make the image non-root again when committing
docker commit -c "USER osuweb" 7f056be66b87 pppy/osu-web:yournewtag
docker push pppy/osu-web:yournewtag