Docker image Flashcards
What is the first step in creating your own image for a container?
For eg. considering running a web application,
- Write down what are the steps you would do if you had to run this web application manually without using container -
- OS - Ubuntu
- Update apt repo
- Install dependencies using apt
- Install Python dependencies using pip
- copy source code to /opt folder
- Run the webserver using “flask” command
- Then create a docker file and write down the procedure for creating the application in it
- Use the docker build command to build the image
There is an image in this studyset with a picture explaining. see that`
How to create your own image to be run in the docker container?
- Write down what are the steps you would do if you had to run this web application manually without using container
- Then create a docker file and write down the procedure for creating the application in it
- Use the docker build command to build the image
Can you write a docker build command to build an image using docker file?
docker build DockerFile -t mumshad/my-custom-app
what does an example docker file look like?
Instruction - Argument format
What are the rules when writing a docker file?
- Start from the base OS or another image
- Install all dependencies
- Copy the source code
- Specify Entry Point
What is meant by the entry point in a docker file?
Whatever we specify in the entry point is the command to be run when the docker creates a container using the image created using that docker file.
How does docker build an image using the docker file?
When Docker builds the images, it builds
these in a layered architecture. Each line of
instruction creates a new layer in the docker
image with just the changes from the
previous layer. For example, the first layer is a base
Ubuntu OS, followed by the second
instruction that creates a second
layer, which installs all the apt packages, and
then the third instruction creates a third layer
with the Python packages, followed by the
fourth layer that copies the source code over,
and the final layer that updates the entry point of the image. Since each layer only stores the changes
from the previous layer, it is reflected in the
size as well.
If you look at the base Ubuntu image, it is
around 120 MB in size. The apt package that
l install is around 300 MB, and the remaining
layers are small.
You could see this information if you run the
docker history command, followed by the
image name. When you run the docker build
command,
I want to create a docker container for running Ubuntu and as soon as the container is up I want to connect to it in an interactive mode and enter bash command?
docker run -it ubuntu bash