0

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
2
  • Which image is it? Do you build that image?
    – seshadri_c
    May 10 at 16:27
  • It is php: image: pimcore/pimcore:PHP7.4-apache
    – Taras
    May 11 at 7:16

1 Answer 1

1

Since you are using a ready-made Docker image, and want additional package(s) on top of it, writing a Dockerfile 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.