Explain the use of Docker commit in detail

  • 2021-09-05 01:18:54
  • OfStack

Sometimes it is necessary to install some dependencies in the basic image. If you write commands in Dockerfile, the software download of some dependencies is slow, and it will take a long time to build the image. Therefore, it is best to repackage a new image containing dependent libraries.

docker provides commit to implement

For example, I have an python image, which is relatively compact. Lack of freetds-dev and unixodbc-dev dependencies.

1. Bring up the mirror run first


docker run -it --name python docker.io/python:3.6.4 /bin/bash

/bin/bash Enter the container to interact

2. Execute the install command


root@39eaa5aa7332:/code# apt-get install freetds-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done

root@39eaa5aa7332:/code# apt-get install unixodbc-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done

After installation, ctrl+p+q exits the container.

3. Package the container into a mirror image and execute docker commit


[root@CentOS ~]# docker commit 39eaa5aa7332 python3.6.4-dev
sha256:ca46b1ed99abc1338881a55a043ee9670a66601530b3f2e63f41eb949b91e84d

Then execute docker images to see this image

The above is a detailed explanation of the use of Docker commit details, more information about the use of Docker commit please pay attention to other related articles on this site!


Related articles: