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

PPTX
Docker Workshop
PDF
Docker in a JS Developer’s Life
PDF
Running the Oracle SOA Suite Environment in a Docker Container
PDF
Docker Essentials Workshop— Innovation Labs July 2020
PDF
Introduction of Docker and Docker Compose
PDF
Dockers Containers in action Slide 0 to hero
PPTX
Docker, LinuX Container
PPTX
Powercoders · Docker · Fall 2021.pptx
Docker Workshop
Docker in a JS Developer’s Life
Running the Oracle SOA Suite Environment in a Docker Container
Docker Essentials Workshop— Innovation Labs July 2020
Introduction of Docker and Docker Compose
Dockers Containers in action Slide 0 to hero
Docker, LinuX Container
Powercoders · Docker · Fall 2021.pptx

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

PDF
Docker use dockerfile
PPTX
Docker 101
PDF
Introduction to Docker
PPTX
PDF
Docker, but what it is?
PDF
Clouds and Tools: Cheat Sheets & Infographics
PPTX
Primi passi con Docker - ItalianCoders - 12-01-2021
DOCX
Docker Compose user guide
PPTX
DockerSADASDASDA SADASDASDASDASDASDLabs.pptx
PDF
dockerizing web application
PPTX
Docker and the Container Ecosystem
PDF
How to write a Dockerfile
PPTX
Hands on introduction to docker security for docker newbies
PDF
Docker.pdf
PPTX
PDF
Docker Up and Running Introduction
PPTX
Learn enough Docker to be dangerous
PPTX
Academy PRO: Docker. Part 2
PPTX
Docker slides
PPTX
Docker Introductory workshop
Docker use dockerfile
Docker 101
Introduction to Docker
Docker, but what it is?
Clouds and Tools: Cheat Sheets & Infographics
Primi passi con Docker - ItalianCoders - 12-01-2021
Docker Compose user guide
DockerSADASDASDA SADASDASDASDASDASDLabs.pptx
dockerizing web application
Docker and the Container Ecosystem
How to write a Dockerfile
Hands on introduction to docker security for docker newbies
Docker.pdf
Docker Up and Running Introduction
Learn enough Docker to be dangerous
Academy PRO: Docker. Part 2
Docker slides
Docker Introductory workshop
Ad

Recently uploaded (20)

PDF
Sciences of Europe No 170 (2025)
PPTX
G5Q1W8 PPT SCIENCE.pptx 2025-2026 GRADE 5
PPTX
Vitamins & Minerals: Complete Guide to Functions, Food Sources, Deficiency Si...
DOCX
Q1_LE_Mathematics 8_Lesson 5_Week 5.docx
PPTX
microscope-Lecturecjchchchchcuvuvhc.pptx
PDF
Unveiling a 36 billion solar mass black hole at the centre of the Cosmic Hors...
PDF
Formation of Supersonic Turbulence in the Primordial Star-forming Cloud
PPTX
Microbiology with diagram medical studies .pptx
PPTX
ECG_Course_Presentation د.محمد صقران ppt
PPTX
cpcsea ppt.pptxssssssssssssssjjdjdndndddd
PDF
Phytochemical Investigation of Miliusa longipes.pdf
PPTX
GEN. BIO 1 - CELL TYPES & CELL MODIFICATIONS
PPTX
TOTAL hIP ARTHROPLASTY Presentation.pptx
PPTX
2. Earth - The Living Planet earth and life
PPTX
Introduction to Fisheries Biotechnology_Lesson 1.pptx
PPTX
famous lake in india and its disturibution and importance
PDF
AlphaEarth Foundations and the Satellite Embedding dataset
PPTX
ognitive-behavioral therapy, mindfulness-based approaches, coping skills trai...
PPTX
INTRODUCTION TO EVS | Concept of sustainability
PDF
Mastering Bioreactors and Media Sterilization: A Complete Guide to Sterile Fe...
Sciences of Europe No 170 (2025)
G5Q1W8 PPT SCIENCE.pptx 2025-2026 GRADE 5
Vitamins & Minerals: Complete Guide to Functions, Food Sources, Deficiency Si...
Q1_LE_Mathematics 8_Lesson 5_Week 5.docx
microscope-Lecturecjchchchchcuvuvhc.pptx
Unveiling a 36 billion solar mass black hole at the centre of the Cosmic Hors...
Formation of Supersonic Turbulence in the Primordial Star-forming Cloud
Microbiology with diagram medical studies .pptx
ECG_Course_Presentation د.محمد صقران ppt
cpcsea ppt.pptxssssssssssssssjjdjdndndddd
Phytochemical Investigation of Miliusa longipes.pdf
GEN. BIO 1 - CELL TYPES & CELL MODIFICATIONS
TOTAL hIP ARTHROPLASTY Presentation.pptx
2. Earth - The Living Planet earth and life
Introduction to Fisheries Biotechnology_Lesson 1.pptx
famous lake in india and its disturibution and importance
AlphaEarth Foundations and the Satellite Embedding dataset
ognitive-behavioral therapy, mindfulness-based approaches, coping skills trai...
INTRODUCTION TO EVS | Concept of sustainability
Mastering Bioreactors and Media Sterilization: A Complete Guide to Sterile Fe...
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