Relay70

Docker Image Modification

Two ways to modify an existing docker image. 
The first way is a standard docker build.
The second way is in case you don't have the original image tar or the docker file.
We will be using the standard Fedora docker image.

1 – Rebuilding with dockerfile

Download image tar and dockerfile

Commands
Explanation
https://hub.docker.com/_/fedora is the docker hub page from the fedora image.  Under the "Docker Files" section it contains a link to this github page.
https://github.com/fedora-cloud/docker-brew-fedora/blob/3474df86c07e56c6e5525e7afc9f34f8ed1dc2aa/x86_64/

The 2 wget commands are simply downloading the docker file and image tar file from this github page.

Update dockerfile

Commands
Explanation
This simply adds the following line to the end of the docker file:
RUN ["dnf", "-y", "install", "python3"]

You can edit the file however you'd like.

Build the new image

Commands
Explanation
This begins the build process.  Using the tar file and info in the dockerfile, the new image will be created.
"-t relay70/fedoreupdate" is tagging the image.
Since we added the RUN line, the last thing the build will do is to execute "dnf install -y python3". Our new image should have python3 installed. The last line if the build, should show:
Successfully built <newImageID>
"docker image ls" should show the new image listed.

Run/Check new image

Commands
Explanation
Using the image ID from the build step start the container.  
"-it --entrypoint sh" tells docker to execute a shell and attach to it.
Since python does not come installed on the standard fedora image, output from the python command shows that our image was successfully updated.

2 – Docker Commit

Pull image from docker hub

Commands
Explanation
Download the image from docker hub
List images and find/note the image ID for the new Fedora image.

Run new image

Commands
Explanation
Run the docker image.
"-it --entrypoint sh" tells docker to execute a shell and attach to it.

Install python

Commands
Explanation
Just like any other dnf install.

Commit image

***Do not disconnect from your container.  The next commands need to be executed in another terminal***
After running the commit command you can exit from your running container.
Commands
Explanation
Execute docker ps to find the container id you've changed.
docker commit <containerID> <repoName> simply saves the container to a new image.

Run/Check new image

Commands
Explanation
List docker images and note the ID for the new image.
Using the image ID from the build step start the container.
"-it --entrypoint sh" tells docker to execute a shell and attach to it.
Since python does not come installed on the standard fedora image, output from the python command shows that our image was successfully updated.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *