How can I run a docker container and commit the changes once a script completes?

后端 未结 4 2066
萌比男神i
萌比男神i 2021-02-14 22:57

I want to set up a cron job to run a set of commands inside a docker container and then commit the changes to the docker image. I\'m able to run the container as a daemon and ge

4条回答
  •  心在旅途
    2021-02-14 23:41

    There are following ways to persist container data:

    1. Docker volumes

    2. Docker commit

      a) create container from ubuntu image and run a bash terminal.

         $ docker run -i -t ubuntu:14.04 /bin/bash
      

      b) Inside the terminal install curl

         # apt-get update
         # apt-get install curl
      

      c) Exit the container terminal

         # exit
      

      d) Take a note of your container id by executing following command :

         $ docker ps -a
      

      e) save container as new image

         $ docker commit  new_image_name:tag_name(optional)
      

      f) verify that you can see your new image with curl installed.

         $ docker images           
      
         $ docker run -it new_image_name:tag_name bash
            # which curl
              /usr/bin/curl
      

提交回复
热议问题