Lev
Lev

Reputation: 1009

Updating a docker image without the original Dockerfile

I am working on Flask app running on ec2 server inside a docker image.

The old dev seems to have removed the original Dockerfile, and I can't seem to find any instructions on a way to push my changes into to the docker image with out the original.

I can copy my changes manually using:

docker cp newChanges.py doc:/root/doc/server_python/

but I can't seem to find a way to restart flask. I know this is not the ideal solution but it's the only idea I have.

Upvotes: 2

Views: 2729

Answers (3)

Adiii
Adiii

Reputation: 59896

There is one way to add newChanges.py to existing image and commit that image with a new tag so you will have a fall back option if you face any issue.

Suppose you run alpine official image and you don't have DockerFile

Everytime you restart the image you will not have your newChanges.py

docker run --rm -name alpine alpine

Use ls inside the image to see a list of existing files that are created in Dockerfile.

docker cp newChanges.py alpine:/

Run ls and verify your file was copied over

Next Step

To commit these changes to your running container do the following:

Docker ps

Get the container ID and run:

docker commit 4efdd58eea8a updated_alpine_image

Now run your alpine image and you will the see the updated changes as suppose

docker run -it updated_alpine_image

This is what you will see in your update_alpine_image with having DockerFile enter image description here

This is how you can rebuild the image from existing image. You can also try @uncletall answer as well.

Upvotes: 3

atline
atline

Reputation: 31564

  • If you just want to restart after docker cp, you can just docker stop $your_container, then docker start $your_container.

  • If you want to update newChanges.py to docker image without original Dockerfile, you can use docker export -o $your_tar_name.tar $your_container, then docker import $your_tar_name.tar $your_new_image:tag. Later, always reserve the tar to backup server for future use.

  • If you want continue to develop later use a Dockerfile in the future for further changes:

    • you can use docker commit to generate a new image, and use docker push to push it to dockerhub with the name something like my_docker_id/my_image_name:v1.0
    • Your new Dockerfile:
    FROM my_docker_id/my_image_name:v1.0
    # your new thing here
    ADD another_new_change.py /root/
    # others

Upvotes: 2

uncletall
uncletall

Reputation: 6842

You can try to examine the history of the image, from there you can probably re-create the Dockerfile. Try using docker history --no-trunc image-name

See this answer for more details

Upvotes: 1

Related Questions