Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Edit Docker Image?

I did a basic search in the community and could not find a suitable answer, so I am asking here. Sorry if it was asked earlier.

Basically , I am working on a certain project and we keep changing code at a regular interval . So ,we need to build docker image everytime due to that we need to install dependencies from requirement.txt from scratch which took around 10 min everytime.

How can I perform direct change to docker image and also how to configure entrypoint(in Docker File) which reflect changes in Pre-Build docker image

like image 397
Error 404 Avatar asked Feb 19 '26 13:02

Error 404


1 Answers

There are 4 Steps

  1. Start the image you want to edit: docker run IMAGE
  2. Modify the running image by shelling into it with docker exec -it <container-id> (you can get the container id with docker ps)
  3. Make any modifications (install new things, make a directory or file)
  4. In a new terminal tab/window run docker commit <container-id> my-new-image (substituting in the container id of the container you want to save)

An example

# Run an existing image
docker run -dt existing_image 

# See that it's running
docker ps
# CONTAINER ID   IMAGE            COMMAND   CREATED              STATUS              
# c7e6409a22bf   existing-image   "R"       6 minutes ago        Up 6 minutes

# Shell into it
docker exec -it c7e6409a22bf bash

# Make a new directory for demonstration purposes
# (note that this is inside the existing image)
mkdir NEWDIRECTORY

# Open another terminal tab/window, and save the running container you modified
docker commit c7e6409a22bf my-new-image

# Inspect to ensure it saved correctly
docker image ls
# REPOSITORY           TAG       IMAGE ID       CREATED         SIZE
# existing-image       latest    a7dde5d84fe5   7 minutes ago   888MB
# my-new-image         latest    d57fd15d5a95   2 minutes ago   888MB
like image 59
stevec Avatar answered Feb 22 '26 08:02

stevec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!