We have written this article for all our new users who doesn’t know anything about using conditions in the docker file.
So, let’s get started.
Open the shell application of Ubuntu 20.04 first. If your system has some old version of docker already installed on it, then you have to make sure that it must be removed. To remove it from our Ubuntu 20.04 Linux system, we have been utilizing Ubuntu’s apt package in the “remove” instruction. On execution of this query, the Ubuntu system has started getting information about the docker.
After getting all the required information about docker packages, it has been showing us the amount of disk space it will release after the removal of those packages. Along with that, it requires your affirmation for the removal process of docker to avoid any inconvenience in the near future. You just need to tap “Y” to continue this process.
The old docker will be removed completely and your system needs to get updated now. To update and upgrade, Linux has provided us with the “apt” package in this regard. Thus, we have utilized it on our shell with the “update” and “upgrade” instructions shown in the below image. Our system got updated and upgraded in a while.
Now, you can use the snap package or apt package to install the newest version of the docker input and output interface. We have been using the apt package here to install it using the “install” instruction followed by the “docker.io” package name.
The command got executed and it started getting information regarding docker from in and out. Within its processing, it will asks you to affirm the installation process on Ubuntu 20.04. You have to press “Y” to continue installing it other press “n” to stop it as shown in the image.
After the docker has been installed, we have loaded all the images of docker in our system using the “docker pull” instruction that has not been mentioned to prevent complexities. We executed the images to create containers and this is what we got after using the “docker ps –a” instruction on the shell. It shows that three containers are available for use.
You need to create a simple bash file via the “touch” instruction below.
Add some if-then bash statement in it that runs some echo statement using the “CMD” keyword after authenticating the user. Save your file for execution.
Before using the containers, we will be creating symlinks using the docker file. We have been creating a new directory “docker” in our main home folder of the system using the “mkdir” instruction shown in the image. The list command has been used to display the before and after results of using the “mkdir” on the shell. The directory “docker” has been created.
$ mkdir docker
We have been moving within the newly created directory “mkdir” using the “cd” instruction and creating a new docker file named “dockerfile” with the use of the “touch” instruction. We have been opening the newly made docker file in the “Vim” editor to create some symlink.
$ vim docker
You have to add the shown below lines on the docker file as the execution data. It contains the main source i.e. “FROM Ubuntu”, the maintainers “simpli” which will be a symlink in our case, and the “RUN” variable shows the command to be executed. It contains a simple “if-then” statement to run the “test.sh” file.
Save this file and quit the editor. Now, you need to build the symlink using the “docker build” instruction along with the path to the docker file. The symlink has been ready for building.
After a while, the symlink will be built using the docker file.
Now, it’s time to link this symlink with a symlink image. For that, you need to use the docker build command along with the path to the file followed by the “-t” flag and the name of an image to be created (i.e. “simpli_image”). Using this instruction, the symlink docker file has been successfully linked to a symlink image.
Now, when we check for the images using the docker images instruction, we got the new image listed at the top.
On running the “docker run” instruction with the image “simpli_image”, the line in the “test.sh” file got executed. This is because of the use of symlink used in the docker file.
This is about the use of conditions in a docker file of the docker platform. We have started with the installation of docker on Ubuntu 20.04. After that, we have created a docker file and added a symlink to it. The “if-then” condition has been used in the docker file and the bash file. Upon running the symlink built by a docker file, we have the message displayed that is a text of bash file while the dicker file symlink has been executed.