0

Is it possible only to modify the FROM value while executing docker commit ?

Say my active container is of Ubuntu 16.04 and I wanted to create an image off it, but Ubuntu version should be of 18.04, rest remains the same.

Does Docker support this scenario ?

Expecting like : docker commit —change=FROM ubuntu:18.04

voltas
  • 553
  • 7
  • 24

2 Answers2

2

The answer is no. You can't modify the base image with docker commit --change=FROM command.

The FROM instruction is not supported for --change option.

Here is the excerpt from the docs:

The --change option will apply Dockerfile instructions to the image that is created. Supported Dockerfile instructions: CMD|ENTRYPOINT|ENV|EXPOSE|LABEL|ONBUILD|USER|VOLUME|WORKDIR

If you don't have dockerfile for your container then, I would suggest to use either:

  • docker history command to generate Dockerfile. As mentioned here.

OR

  • Use dfimage utiliyy as mentioned here.

And then change the FROM instruction in your new generated dockerfile.

mchawre
  • 10,744
  • 4
  • 35
  • 57
2

This is a strong reason to never use docker commit.

If you have a commit-based workflow, you need to docker run a container from some base image, perform some steps, and commit the result. Once you've done this, though, Docker has no idea what happened in between; it just knows that there's an image, and some opaque set of filesystem changes, and it's being asked to create an image from that.

Say you're using an old version of Ubuntu, and you want to upgrade to something newer. In a commit-based workflow, it's up to you to do all of the steps by hand. To keep track of this, you might write down a text file of the steps you want to perform:

# `docker run` a container using this base image
FROM ubuntu:18.04
# `docker cp` this file into the image
COPY package.deb /
# Run this command in the container shell
RUN dpkg -i /package.deb
# After committing the image, `docker run` the new image with this command
CMD some_command

That specific format is exactly the Dockerfile format, though: you can check it into source control, run docker build, and get the image back. Your coworker can do that too even if they don't have the exact setup you do, and even if they don't type the commands exactly the same way. And when you do need to upgrade the base image, you can just change the first line to FROM ubuntu:20.04 and docker build it again.

David Maze
  • 130,717
  • 29
  • 175
  • 215