Docker Image Operations - Create a New Image by Writing Over an Existing Image: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Image Operations * Dockerfile =Overview= This example demonstrate how to modify an existing Postgresql imag...")
 
 
(One intermediate revision by the same user not shown)
Line 6: Line 6:
=Overview=
=Overview=


This example demonstrate how to modify an existing Postgresql image to add debugging output to the setup logic.
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=
=Procedure=
Line 19: Line 19:
FROM registry.access.redhat.com/rhscl/postgresql-95-rhel7:latest
FROM registry.access.redhat.com/rhscl/postgresql-95-rhel7:latest
COPY ./run-postgresql /usr/bin/
COPY ./run-postgresql /usr/bin/
</syntaxhighlight>


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:
<syntaxhighlight lang='docker'>
FROM ...
CMD ["my-app", "--debug", "start"]
</syntaxhighlight>
</syntaxhighlight>


Line 27: Line 33:


The new image will be placed in the local registry as "novaordis/postgresql-debug:latest".
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==
==Run the Image==


  docker run -e -e POSTGRESQL_USER=... -e POSTGRESQL_PASSWORD=... -e POSTGRESQL_DATABASE=... novaordis/postgresql-debug
  docker run -e -e POSTGRESQL_USER=... -e POSTGRESQL_PASSWORD=... -e POSTGRESQL_DATABASE=... novaordis/postgresql-debug

Latest revision as of 22:34, 15 August 2019

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