Modifying a container image
Modifying a container imageCurrently, procedures for this feature are only provided for Docker containers.
There may be a desire to make a change within a Docker container image and then use that updated image in an experiment. For example, you could make changes to the source code of a component, or modify default tables of a software component, etc. You The command docker commit allows one to save changes made within an existing container to a new image for future use.
In this example, we'll modify the wps_wrf container. Assuming you already have the wps_wrf:4.0.0 image pulled from Dockerhub (4.0.0. being the previously set ${PROJ_VERSION} variable), you should see your images following the docker images command. For example:
dtcenter/wps_wrf 4.0.0 3d78d8d63aec 2 months ago 3.81GB
We will deploy the container similar to running a component in our example cases, however with a few key difference. First, we'll omit the "--rm" option from the command so that when we exit the container it is not removed from our local list of containers and the changes persist in a local container. For simplicity, we'll also omit the mounting of local directories. Finally, we'll substitute our typical run command from a provided script to a simple /bin/bash. This allows us to enter the container in a shell environment to make changes and test any modifications.
[comuser@d829d8d812d6 wrf]$
Note the change in command prompt to something similar to: [comuser@d829d8d812d6 wrf]$, highlighting that you are now inside the container, and not on your local machine space. Do an "ls" to list what's in this container:
WPS-4.3 WRF WRF-4.3
Inside the container, you can now make any edits you want. You could make an edit to the WRF or WPS source code and recompile the code, or your make edits to predefined tables. For the purposes of illustrating the general concept of docker commit, we'll just add a text file in the container so we can see how to make it persist in a new image.
ls
Now exit the container.
You are now back on your local command line. List your containers to find the name of the container that you just modified and exited:
d829d8d812d6 dtcenter/wps_wrf:4.0.0 "/usr/local/bin/entr…" 33 seconds ago Exited (0) 20 seconds ago sweet_moser
Note the container d829d8d812d6 that we just exited. This is the container name id that we'll use to make a new image. Use docker commit to create a new image from that modified container. The general command is:
docker commit CONTAINER_ID_NAME NEW_IMAGE_NAME
So in this example:
Execute a docker images command to list your images and see the new image name.
wps_wrf_testfile latest f490d863a392 3 seconds ago 3.81GB
dtcenter/wps_wrf 4.0.0 3d78d8d63aec 2 months ago 3.81GB
You can deploy this new image and enter the container via a shell /bin/bash command to confirm this new image has your changes, e.g.:
useradd: user 'user' already exists
[comuser@05e6fb4618dd wrf]$
In the container, now do a "ls" to list the contents and see the test file.
Exit the container.
Once you have this new image, you can use it locally as needed. You could also push it to a Dockerhub repository where it will persist beyond your local machine and enable you to use docker pull commands and share the new image if needed.