two Ways to create docker images
-
interactively : manually run container and then save as an image
-
Dockerfile (instructions-based): build image based instructions (automatically create image)
-
interactively method:
- first need run container
docker run -d --name web1 -p 80:80 nginx
download sample website
mkdir website
cd website
wget https://www.tooplate.com/download/2168_sweet_bakery
cp 2168_sweet_bakery 2168_sweet_bakery.zip
sudo apt install unzip
unzip 2168_sweet_bakery.zip
docker cp . web1:/usr/share/nginx/html/
out put
Successfully copied 817kB (transferred 828kB) to web1:/usr/share/nginx/html/
verify server by access port 80
http://20.46.241.140/
svae the container
docker commit web1 2168_sweet_bakery:1.2.0
docker images
docker run -d --name sweet_bakery -p 8080:80 2168_sweet_bakery:latest
- Dockerfile referance
- to create image we need follow docker instructions
-
FROM – base image (os image or required configuation image ) Ex: ubuntu , oracle-linux, alpine (lite weight linux kernal os), java, python, dotnet, windows-dotnet …etc
-
WORKDIR – set working directory in docker image
-
COPY – copy local files to my docker image
-
ADD – downloads files or packages
-
RUN – Execute commands during build ex:
alpine - apk add git
ubuntu - apt-get install git -y
oracle-linux - yum install git -y
windows - winget install git -y
- EXPOSE – application ports
- CMD – command to run when container start ex: java -jar spring.jar
- entrypoint – run first command when container start
task:
- create docker image using interactively method
- https://www.tooplate.com/free-templates free templates
