Docker Image Operations - Create a New Image by Writing Over an Existing Image
Jump to navigation
Jump to search
Internal
Overview
This example demonstrate how to modify an existing Postgresql image by creating a new image with a very thin modification on top. In this case we add debugging output to the setup logic in form of a new run script. Alternatively, we can modify the CMD sequence and layer it in top of the existing image.
Procedure
Stage New Content
Use the local directory as staging area. Place a new run-postgreql with extra debug output.
Write the Dockerfile
FROM registry.access.redhat.com/rhscl/postgresql-95-rhel7:latest
COPY ./run-postgresql /usr/bin/
Alternatively (we are assuming a hypothetical my-app that can be started in debug mode by passing --debug, which did not exist in the "FROM" image:
FROM ...
CMD ["my-app", "--debug", "start"]
Build the Image
docker build -t novaordis/postgresql-debug .
The new image will be placed in the local registry as "novaordis/postgresql-debug:latest".
Verifiy
In case CMD was modified, run "inspect" to make sure the CMD has been update in the "Config"/"Cmd" section.
docker inspect <new-image-id>
Run the Image
docker run -e -e POSTGRESQL_USER=... -e POSTGRESQL_PASSWORD=... -e POSTGRESQL_DATABASE=... novaordis/postgresql-debug