Question-31: Can you please tell which command you can use to build new Docker container?
Answer: You can use command “docker build” . For example
docker run -t hadoopexam-image
It would create a new Docker image named “hadoopexam-image”
Question-32: What is the command you can use to run Docket image?
Answer: You can use “docker run” command to run the Docker Image.
Question-33: What happens when you remove files from existing container?
Answer: When you remove files from the container then they remain in the image. But your new layer would not have this and you cannon access this. If you are experimenting then it can create large image. For example
LayerA: HE1File.txt
LayerB: Remove HE1File.txt
LayerC: Add new file HE2File.txt
You think that HE1File.txt is no longer present on your Docker Image. But that is not true. And when you run the image this file is not accessible. However, the file added at LayerA is still there. And whenever you download this image this file always come with Image and this is not good as you don’t want this file but unnecessarily taking more space and consuming more network bandwidth whenever downloaded.
Question-34: Can you explain why it is said that you should order layers for image which are least likely to change?
Answer: to understand let’s take two example of the container layer
In Example-1 we have three layers as below
- LayerA:BaseOS
- LayerB:add file HadoopExam.java
- LayerC: Install java11
In Example-2 we have three layers as below
- LayerA:BaseOS
- LayerB: Install java11
- LayerC:add file HadoopExam.java
Now, you want to update the HadoopExam.java file. In first case you need both layer HadoopExam.java and Java11 needs to be pulled and pushed, because Java11 layer is depend on the HadoopExam.java layer. If you see Example-2 in this case you have to change only HadoopExam.java layer and need to pull and push. That’s why it is important you need to layer your image which is least likely to change. This is a simple example but what if we have many layers in image.
Question-35: Is it ok if containers lower layers are having password in it?
Answer: Not at all, you should never have password stored in any layer of the container. This is not a good practice. This can be easily cracked with the tools.