How do I create a custom image?
Navigate to the 'Containers' module, then click on 'Images'.
If you are about to create your very first custom image, you should see a message similar to the one shown below. Click the 'Create Custom Image' button to get started:
You will now need to enter the name for your custom image, and whether you would like to fork this image from one of our pre-made images. In this case we are going to fork from the
Apache + PHP 7.0image.
Learn more about the difference between forking an image and starting from scratch.
If this is your first custom image, you won't have any SSH keys that have access. We will select our SSH key and click 'Create Image', this allows you to clone the image to your local machine.
Read more about SSH Keys and custom images.
You will now see that your custom image is in the progress of being created. This should only take a few moments, once your image is created click on its name to see more details.
Here we can see all of the details about our custom image, the repository url (which we will use shortly) and the current image versions if you have some.
Learn more about image versions.
We will now clone the repository to our local machine. We are assuming that you already have git installed, if not install it now.
$ git clone firstname.lastname@example.org:g_1/my-custom-image.git $ cd ./my-custom-image
Inside our repository you will find all the files and folder structure we need to build a custom image.
$ ls -lah > drwxrwxr-x 6 user user 4.0K Nov 28 12:04 default-data > -rw-rw-r-- 1 user user 67 Nov 28 12:04 Dockerfile > drwxrwxr-x 8 user user 4.0K Nov 28 12:04 .git > -rw-rw-r-- 1 user user 605 Nov 28 12:04 .gitlab-ci.yml > -rw-rw-r-- 1 user user 393 Nov 28 12:04 manifest.yml
As you can see our repository contains 3 files:
DockerfileThese 3 files are mandatory in every custom image, they define exactly how to build your custom image.
When making a custom image from scratch, you will mainly be changing
Dockerfile. You can read more about the manifest.yml file.
.gitlab-ci.ymlfile is used to build your custom image in our CI environment, we do not allow any changes to this file. Any commit that alters this file will be rejected.
You will also notice the
default-datadirectory. This is where you store the files needed for your custom image. For more information please read about the default-data directory.
Because we forked our image from the
Apache + PHP 7.0image, you will see inside
default-dataall the necessary files needed for this image.
Let's change the index.html to index.php
$ rm ./default-data/application/public/index.html $ echo "<?php phpinfo() ?>" > ./default-data/application/public/index.php
We will now add those changes to our commit and push the changes. This will trigger an automatic build.
$ git rm ./default-data/application/public/index.html $ git add ./default-data/application/public/index.php $ git commit -m "remove index.html, adding index.php" $ git push
While the image is building, you can view the build status and build log from within the Control Panel. For more information, you can read about the build status and build log.
Check the build status
We can now see that our build was successful:
Once an image has successfully finished building, you can now use it when creating containers.