2 1docker
2 1docker
2 1docker
1
Student Name: Sudhir Yadav UID: 21CDO1041
Branch: AIT – CSE (DevOps) Section/Group: 21BCD – 1(A)
Semester: 5th Date of Performance: 4 Sep, 2023
Subject Name: Docker and Kubernetes Subject Code: 21CSH - 349
2. Task to be done :
Use JavaScript for designing dynamic web pages and client side validation.
Make Docker Account, deploy an application on Docker and install Virtual Docker on
local machine and access files from Docker account
3. Theory
A script called a Dockerfile gives directions for creating a customized Docker image. The final
image is made up of all the layers stacked on top of one another, and each instruction in a
Dockerfile adds a new layer to the image.
It contains instructions for establishing environment variables, transferring files, installing
dependencies, and customizing the container.
Any text editor can be used to generate and amend Dockerfile because of its straightforward,
understandable syntax. A Dockerfile can be used to construct an image by using the docker
build command after it has been prepared. Using the docker run command, the generated image
can then be used as a container.
To create and manage test environments for various apps and services, Dockerfiles can be used
in automation testing. Without having to manually set up and configure the environment on
each test run, you may use a Dockerfile to produce an image of a particular test environment
that can be reliably and simply repeated.
A continuous integration and continuous deployment (CI/CD) pipeline, which enables you to
automatically build, test, and deploy your application with every code change, may be simply
integrated with your Dockerfile. This lowers the possibility of errors and guarantees that your
application is always current.
2) FROM
The FROM instruction specifies the base image that the container will be built on top of. This
instruction is typically the first one in a Dockerfile and is used to set the base image for the
container. The format of the instruction is:
FROM <image>
3) WORKDIR
In a Dockerfile, the WORKDIR instruction sets the working directory for any command that
follows it in the Dockerfile. This means that any commands that are run in the container will be
executed relative to the specified directory. Below is the format of the instruction :
WORKDIR <directory>
4) COPY
Use the COPY instruction to copy local files from the host machine to the current working
directory. For example, to copy a file named package.json from the host machine’s current
directory to the image’s /app directory, you would use the following command:
COPY . .
5) RUN
Use the “RUN” instruction to execute commands that will run during the image build process.
The format of instruction is :
RUN <command_name>
6) CMD
In a Dockerfile, the CMD instruction sets the command that will be executed when a container
is run from the image. The format of the instruction is:
CMD ["executable","param1","param2",...]
Running a Dockerfile:
After creating a Dockerfile, now let’s explore the process of building a Dockerfile, pushing it to
a registry, and then running it.
Pre-Requisite for push: You need to login ( use command: docker login)
Once the image is built, you can check if it got created by using the below command:
docker images
The above command will show you all the docker images.
Once, the docker image is built and now you can push your docker image. You can tag the
image first and then push it or you can push it directly as well. Sometimes, there is an access
denied issue even though you are logged in. In that scenario, you can tag the image first and
then push it.
Once you tag the image, now you can push the image using the below commands:
Syntax:
Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):