How to create custom Drupal image in Dockerfile?

I’m a student, New to docker. We should create Docker compose and include a custom Drupal image and postgres image.

I’m trying to create a custom Drupal image in docker file but don’t know what exactly to add to the RUN WORKDIR CMD

I know their functionalities (what to write in them)

I reviewed the base images with different tags on Docker hub but can’t figure out what to include still.

Thanks in advance for helping me in my learning journey.

It depends on how “custom” that image should be. You can just add a LABEL and you have a custom image. If you have a specific issue, a goal that you want to achieve, we can try to help you, but otherwise there is not much we can tell you. Please, explain your issue in more details.

I’m supposed to : Write a basic compose file for a Drupal content management system website.
This compose file should include ‘custom’ Drupal image for local testing and postgres image.

The only spcifications they gave about this Drupal custom image is:
-Use volumes to store Drupal unique data.
-Use ports to expose Drupal on 8080 so you can localhost:8080.

so, I don’t know what to write in this custom image.

Have you tried to search for the two keywords you got from the school? “volume” and “expose” with the word “Dockerfile”?

Since this is a very basic task I let you search for it. Sorry, but otherwise it wouldn’t actually be your work. However I can tell you this:

Even though your task seems to be using the VOLUME and EXPOSE instructions in a Dockerfile, I wouldn’t use VOLUME and EXPOSE is usually not required. If this is what your teacher wants you to practice, then of course you need to do that. Normally I would not define a volume in a Dockefile, because you can’t remove it if you decide not to use a volume when you run a container from the image. In most cases I would only document what folder is supposed to be a mount point of a volume and let people use the -v option of docker run or the volumes block in a Docker Compose file.

The EXPOSE instruction just sets a metadata which can be read by other softwares or a real person to determine which port the process is listening on in the container. Unless you use the -p option of docker run or the ports block in a Docker Compose file, the port will only be available on the container’s IP address. In case of Docker Desktop you can’t even use that, since everything is in a virtual machine.

Additionally some ideas what you could be customized in a Drupal docker image.

  • You could COPY a configuration file into the image

  • You could RUN apt-get install or apk add depending on what the operating system is in the image and you can install some additional softwares like new php dependencies

  • You can add a LABEL to add a maintainer like this:

    LABEL maintainer="your name"