SlideShare a Scribd company logo
Docker file
➢ Docker Image:
A Docker Image is a read-only file with a bunch of instructions. When these instructions are executed, it
creates a Docker container.
➢ Dockerfile:
Dockerfile is a simple text file that consists of instructions to build Docker images.
➢ Syntax
# comments
command argument argument1...
➢ Docker Commands for Creating a Dockerfile
CMD - Specifies what command to run within the container
FROM - Creates a layer from the ubuntu:18.04
FROM ubuntu:18.04
PULL - Adds files from your Docker repository
PULL. /file
RUN - Builds your container
RUN make /file
CMD python /file/file.py
• allows specifying a command along with the parameters
• Syntax, ENTRYPOINT application "arg, arg1".
• Example , ENTRYPOINT echo "Hello, $name".
ENTRYPOINT
• ADD command helps in copying data into a Docker image
• Syntax , ADD /[source]/[destination]
• Example , ADD /root_folder/test_folder
ADD
• ENV provides default values for variables that can be accessed within the container
• Syntax , ENV key value
• Example , ENV value_1
ENV
• MAINTAINER declares the author field of the images
• Syntax , MAINTAINER [name]
• Example , MAINTAINER author_name
MAINTAINER
Docker Commands
network Manage networks
volume Manage volumes
Name Description
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container’s changes
config Manage Swarm configs
container Manage containers
cp Copy files/folders between a container and the local filesystem
create Create a new container
exec Execute a command in a running container
export Export a container’s filesystem as a tar archive
image Manage images
images List images
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
port List port mappings or a specific mapping for the container
ps List containers
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Create and run a new container from an image
save
Save one or more images to a tar archive (streamed to STDOUT by
default)
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
top Display the running processes of a container
Build a Docker Image with Dockerfile
➢ Create a directory where the dockerfile will be stored.
▪ mkdir c1 && cd c1
➢ Create dockerfile
▪ sudo vi dockerfile
####Contents of Dockerfile####
FROM ubuntu:22.04
MAINTAINER Virtual_University_of_Pakistan
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y ubuntu-server
EXPOSE 2022
#expose the port 2022
CMD ["echo", "Welcome to it601p"]
#above command will print the message and container will exit.
#To keep it running run bash and keep it running
CMD [“PROGRAM_TO_RUN”]
Build a Docker Image with Dockerfile
➢ Build the image using above docker file
▪ docker build --help
▪ docker build <options>
Option Description
--build-arg Set build-time variables
--cache-from Images to consider as cache sources
--cgroup-parent Optional parent cgroup for the container
--compress Compress the build context using gzip
--cpu-period Limit CPU CFS (Completely Fair Scheduler) period
--cpu-quota Limit the CPU CFS (Completely Fair Scheduler) quota
--cpu-shares , -c CPU shares (relative weight)
--cpuset-cpus CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems MEMs in which to allow execution (0-3, 0,1)
--disable-content-trust TRUE, Skip image verification
--iidfile Write the image ID to the file
--isolation Container isolation technology
--memory , -m Memory limit
--memory-swap
Swap limit equal to memory plus swap: -1 to enable unlimited
swap
--no-cache Do not use cache when building the image
--platform Set platform if server is multi-platform capable
--pull Always attempt to pull a newer version of the image
--security-opt Security options
--shm-size Size of /dev/shm
--squash Squash newly built layers into a single new layer
--target Set the target build stage to build.
--ulimit Ulimit options
➢ Some Options
--file, -f : docker file name
--label : set meta data for image
--quite -q : suppress output
--rm : Remove intermediate containers
--tag, -t : set name or tag
--add-host : Add custom host to IP mapping
--network : set the networking mode for run commands
➢ Upon completion , it returns the image id
Build a Docker Image with Dockerfile
➢ Verify the image is crated
▪ docker images
➢ Run an image
▪ docker run name:tag <options>
--workdir , -w Working directory inside the container
--hostname , -h Container host name
--interactive , -i Keep STDIN open even if not attached
--ip IPv4 address (e.g., 172.30.100.104)
--label , -l Set meta data on a container
--link Add link to another container
--mount Attach a filesystem mount to the container
--name Assign a name to the container
--network Connect a container to a network
--rm Automatically remove the container when it exits
--mac-address Container MAC address (e.g., 92:d0:c6:0a:29:33)
--memory , -m Memory limit
--volume , -v Bind mount a volume
Create a New Container
Now, create a Docker container from the Docker image we created in the previous step.
docker run --name it601p_m1

More Related Content

Similar to Computer science docker file Week -6 to7 (20)

PDF
Docker use dockerfile
cawamata
 
PPTX
Docker 101
schmidtbt
 
PDF
Introduction to Docker
Kuan Yen Heng
 
PPTX
Docker
Dmitry Bolgarov
 
PDF
Docker, but what it is?
Julien Maitrehenry
 
PDF
Clouds and Tools: Cheat Sheets & Infographics
Thomas Poetter
 
PPTX
Primi passi con Docker - ItalianCoders - 12-01-2021
Alessandro Mignogna
 
DOCX
Docker Compose user guide
VAIBHAV GUPTA
 
PPTX
DockerSADASDASDA SADASDASDASDASDASDLabs.pptx
MuhamedAhmed35
 
PDF
dockerizing web application
Walid Ashraf
 
PPTX
Docker and the Container Ecosystem
psconnolly
 
PDF
How to write a Dockerfile
Knoldus Inc.
 
PPTX
Hands on introduction to docker security for docker newbies
Yigal Elefant
 
PDF
Docker.pdf
UsamaMushtaq24
 
PPTX
Docker
Mutlu Okuducu
 
PDF
Docker Up and Running Introduction
Mark Beacom
 
PPTX
Learn enough Docker to be dangerous
David Tan
 
PPTX
Academy PRO: Docker. Part 2
Binary Studio
 
PPTX
Docker slides
Ayla Khan
 
PPTX
Docker Introductory workshop
Runcy Oommen
 
Docker use dockerfile
cawamata
 
Docker 101
schmidtbt
 
Introduction to Docker
Kuan Yen Heng
 
Docker, but what it is?
Julien Maitrehenry
 
Clouds and Tools: Cheat Sheets & Infographics
Thomas Poetter
 
Primi passi con Docker - ItalianCoders - 12-01-2021
Alessandro Mignogna
 
Docker Compose user guide
VAIBHAV GUPTA
 
DockerSADASDASDA SADASDASDASDASDASDLabs.pptx
MuhamedAhmed35
 
dockerizing web application
Walid Ashraf
 
Docker and the Container Ecosystem
psconnolly
 
How to write a Dockerfile
Knoldus Inc.
 
Hands on introduction to docker security for docker newbies
Yigal Elefant
 
Docker.pdf
UsamaMushtaq24
 
Docker Up and Running Introduction
Mark Beacom
 
Learn enough Docker to be dangerous
David Tan
 
Academy PRO: Docker. Part 2
Binary Studio
 
Docker slides
Ayla Khan
 
Docker Introductory workshop
Runcy Oommen
 

Recently uploaded (20)

PPTX
MATTER.pptxBYUHNJMIK,O.LBYHNUJMIK,OL.PN8M9,0L.-;/
emelitamaranga
 
PPTX
SCHOOL HOLIDAY REVISION CHAPTER 8.pptx science kssm
SITIATHIRAHBINTISULA
 
PDF
Impacts on Ocean Worlds Are Sufficiently Frequent and Energetic to Be of Astr...
Sérgio Sacani
 
PDF
Electromagnetism 3.pdf - AN OVERVIEW ON ELECTROMAGNETISM
kaustavsahoo94
 
PDF
Human-to-Robot Handovers track - RGMC - ICRA 2025
Alessio Xompero
 
PDF
Therapeutic, Functional and Neutralizing Antibodies Recognize Discontinuous, ...
stavejw
 
PPTX
FACTORS PREDISPOSING TO MICROBIAL PATHOGENICITY.pptx
Remya M S
 
PPTX
Philippine_Literature_Precolonial_Period_Designed.pptx
josedalagdag5
 
PPT
rate of reaction and the factors affecting it.ppt
MOLATELOMATLEKE
 
PDF
Voyage to the Cosmos of Consciousness.pdf
Saikat Basu
 
PDF
Thermal stratification in lakes-J. Bovas Joel.pdf
J. Bovas Joel BFSc
 
PPTX
GENERAL BIOLOGY 1QUARTER 1 MODULE 1 CELL THEORY PPT
MOJANAABIGAILLLAGUNO
 
PDF
The MUSEview of the Sculptor galaxy: survey overview and the planetary nebula...
Sérgio Sacani
 
PPTX
Operating_a_Microscope_Presentation.pptx
MerylVelardeCapapas
 
PDF
The Diversity of Exoplanetary Environments and the Search for Signs of Life B...
Sérgio Sacani
 
PDF
Isro (Indian space research organization)
parineetaparineeta23
 
PPTX
Level 3 Food Safety training for food handlers
nibbuchadnizar
 
PDF
CERT Basic Training PTT, Brigadas comunitarias
chavezvaladezjuan
 
PPTX
PROTECTED CULTIVATION ASSIGNMENT 2..pptx
RbDharani
 
PDF
Bacterial microbes kal growth by Atlas.pdf
adimondal300
 
MATTER.pptxBYUHNJMIK,O.LBYHNUJMIK,OL.PN8M9,0L.-;/
emelitamaranga
 
SCHOOL HOLIDAY REVISION CHAPTER 8.pptx science kssm
SITIATHIRAHBINTISULA
 
Impacts on Ocean Worlds Are Sufficiently Frequent and Energetic to Be of Astr...
Sérgio Sacani
 
Electromagnetism 3.pdf - AN OVERVIEW ON ELECTROMAGNETISM
kaustavsahoo94
 
Human-to-Robot Handovers track - RGMC - ICRA 2025
Alessio Xompero
 
Therapeutic, Functional and Neutralizing Antibodies Recognize Discontinuous, ...
stavejw
 
FACTORS PREDISPOSING TO MICROBIAL PATHOGENICITY.pptx
Remya M S
 
Philippine_Literature_Precolonial_Period_Designed.pptx
josedalagdag5
 
rate of reaction and the factors affecting it.ppt
MOLATELOMATLEKE
 
Voyage to the Cosmos of Consciousness.pdf
Saikat Basu
 
Thermal stratification in lakes-J. Bovas Joel.pdf
J. Bovas Joel BFSc
 
GENERAL BIOLOGY 1QUARTER 1 MODULE 1 CELL THEORY PPT
MOJANAABIGAILLLAGUNO
 
The MUSEview of the Sculptor galaxy: survey overview and the planetary nebula...
Sérgio Sacani
 
Operating_a_Microscope_Presentation.pptx
MerylVelardeCapapas
 
The Diversity of Exoplanetary Environments and the Search for Signs of Life B...
Sérgio Sacani
 
Isro (Indian space research organization)
parineetaparineeta23
 
Level 3 Food Safety training for food handlers
nibbuchadnizar
 
CERT Basic Training PTT, Brigadas comunitarias
chavezvaladezjuan
 
PROTECTED CULTIVATION ASSIGNMENT 2..pptx
RbDharani
 
Bacterial microbes kal growth by Atlas.pdf
adimondal300
 
Ad

Computer science docker file Week -6 to7

  • 1. Docker file ➢ Docker Image: A Docker Image is a read-only file with a bunch of instructions. When these instructions are executed, it creates a Docker container. ➢ Dockerfile: Dockerfile is a simple text file that consists of instructions to build Docker images. ➢ Syntax # comments command argument argument1... ➢ Docker Commands for Creating a Dockerfile CMD - Specifies what command to run within the container FROM - Creates a layer from the ubuntu:18.04 FROM ubuntu:18.04 PULL - Adds files from your Docker repository PULL. /file RUN - Builds your container RUN make /file CMD python /file/file.py
  • 2. • allows specifying a command along with the parameters • Syntax, ENTRYPOINT application "arg, arg1". • Example , ENTRYPOINT echo "Hello, $name". ENTRYPOINT • ADD command helps in copying data into a Docker image • Syntax , ADD /[source]/[destination] • Example , ADD /root_folder/test_folder ADD • ENV provides default values for variables that can be accessed within the container • Syntax , ENV key value • Example , ENV value_1 ENV • MAINTAINER declares the author field of the images • Syntax , MAINTAINER [name] • Example , MAINTAINER author_name MAINTAINER
  • 3. Docker Commands network Manage networks volume Manage volumes Name Description attach Attach local standard input, output, and error streams to a running container build Build an image from a Dockerfile commit Create a new image from a container’s changes config Manage Swarm configs container Manage containers cp Copy files/folders between a container and the local filesystem create Create a new container exec Execute a command in a running container export Export a container’s filesystem as a tar archive image Manage images images List images inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN port List port mappings or a specific mapping for the container ps List containers rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images run Create and run a new container from an image save Save one or more images to a tar archive (streamed to STDOUT by default) stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers top Display the running processes of a container
  • 4. Build a Docker Image with Dockerfile ➢ Create a directory where the dockerfile will be stored. ▪ mkdir c1 && cd c1 ➢ Create dockerfile ▪ sudo vi dockerfile ####Contents of Dockerfile#### FROM ubuntu:22.04 MAINTAINER Virtual_University_of_Pakistan ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && apt-get install -y ubuntu-server EXPOSE 2022 #expose the port 2022 CMD ["echo", "Welcome to it601p"] #above command will print the message and container will exit. #To keep it running run bash and keep it running CMD [“PROGRAM_TO_RUN”]
  • 5. Build a Docker Image with Dockerfile ➢ Build the image using above docker file ▪ docker build --help ▪ docker build <options> Option Description --build-arg Set build-time variables --cache-from Images to consider as cache sources --cgroup-parent Optional parent cgroup for the container --compress Compress the build context using gzip --cpu-period Limit CPU CFS (Completely Fair Scheduler) period --cpu-quota Limit the CPU CFS (Completely Fair Scheduler) quota --cpu-shares , -c CPU shares (relative weight) --cpuset-cpus CPUs in which to allow execution (0-3, 0,1) --cpuset-mems MEMs in which to allow execution (0-3, 0,1) --disable-content-trust TRUE, Skip image verification --iidfile Write the image ID to the file --isolation Container isolation technology --memory , -m Memory limit --memory-swap Swap limit equal to memory plus swap: -1 to enable unlimited swap --no-cache Do not use cache when building the image --platform Set platform if server is multi-platform capable --pull Always attempt to pull a newer version of the image --security-opt Security options --shm-size Size of /dev/shm --squash Squash newly built layers into a single new layer --target Set the target build stage to build. --ulimit Ulimit options ➢ Some Options --file, -f : docker file name --label : set meta data for image --quite -q : suppress output --rm : Remove intermediate containers --tag, -t : set name or tag --add-host : Add custom host to IP mapping --network : set the networking mode for run commands ➢ Upon completion , it returns the image id
  • 6. Build a Docker Image with Dockerfile ➢ Verify the image is crated ▪ docker images ➢ Run an image ▪ docker run name:tag <options> --workdir , -w Working directory inside the container --hostname , -h Container host name --interactive , -i Keep STDIN open even if not attached --ip IPv4 address (e.g., 172.30.100.104) --label , -l Set meta data on a container --link Add link to another container --mount Attach a filesystem mount to the container --name Assign a name to the container --network Connect a container to a network --rm Automatically remove the container when it exits --mac-address Container MAC address (e.g., 92:d0:c6:0a:29:33) --memory , -m Memory limit --volume , -v Bind mount a volume
  • 7. Create a New Container Now, create a Docker container from the Docker image we created in the previous step. docker run --name it601p_m1