How can I run apt-get update and apt-get upgrade commands automatically?



  • I have a docker container where I run a few commands as a root user each time it is created from an image. Is it possible to automate running these commands as a root administrator user each time my container is created?

    # apt-get update
    

    apt-get upgrade

    apt-get install -y vim


  • QA Engineer

    Since you are using a ready-made Docker image, and want additional package(s) on top of it, writing a https://docs.docker.com/engine/reference/builder/ would be "automation" of the commands. Using this you can create a new image with what you want pre-installed.

    Example Dockerfile:

    FROM pimcore/pimcore:PHP7.4-apache
    

    RUN apt-get update && apt-get upgrade && apt-get install -y vim

    Then use the docker build command to build an image with a name (tag) that you want.

    Example below creates image named my-phpapache:7.4, you can use a name that makes sense to you. This image will have vim installed.

    docker build -t my-phpapache:7.4 .
    

    Note the ., this should be run in the same directory as the Dockerfile.

    You may find that using the Dockerfile to copy configuration into the image may eliminate the need to have vim installed in it.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2