Yin amfani da hanya ce mai ƙarfi don ginawa da keɓancewa a ciki. Anan ga cikakken tsari da takamaiman misali na amfani da ginawa da keɓancewa: Dockerfile images
Docker Dockerfile image
Ƙirƙiri a Dockerfile
Fara da ƙirƙirar sabon fayil ɗin rubutu da sanya masa suna. Dockerfile
Ƙayyade tushe image
Yi amfani da FROM
umarnin don saka hoton tushe don sabon image
. Hoton tushe na iya zama data kasance image
daga Docker Hub
ko wani hoton da kuka gina a baya.
Misali, don amfani da Ubuntu 20.04 image
matsayin tushe image
, zaku iya amfani da umarni mai zuwa:
FROM ubuntu:20.04
Yi umarnin shigarwa da daidaitawa
Yi amfani da RUN
umarnin don aiwatar da umarni yayin aikin ginin hoto. Kuna iya amfani da umarnin shigarwa don fakitin software, daidaitawar yanayi, ƙirƙirar kundayen adireshi, da yin wasu ayyuka masu mahimmanci.
Misali, don shigar da Nginx a cikin image
, zaku iya amfani da umarni mai zuwa:
RUN apt-get update && apt-get install -y nginx
Yi la'akari da abin da kuke so image
Kwafi fayiloli da kundayen adireshi zuwa cikin image
: Yi amfani da COPY
umarnin don kwafi fayiloli da kundayen adireshi daga na'ura mai ɗaukar hoto zuwa cikin image
. Kuna iya kwafin fayilolin tushen, kundayen adireshi na aikace-aikace, fayilolin sanyi, da sauran albarkatu cikin image
.
Misali, don kwafi app
kundin adireshi daga injin mai watsa shiri zuwa ga /app
directory a cikin image
, zaku iya amfani da umarni mai zuwa:
COPY app /app
Ƙayyade tsohuwar umarnin lokacin farawa a container
Yi amfani da CMD
umarnin don ƙayyade tsohuwar umarnin da za a aiwatar lokacin da container
aka fara daga image
. Umurnin CMD
yana bayyana babban shirin ko umarni cewa kwandon zai gudana yayin farawa.
Misali, don fara Nginx a cikin container
, zaku iya amfani da umarni mai zuwa:
CMD ["nginx", "-g", "daemon off;"]
Gina image
daga Dockerfile
Yi amfani da docker build
umarnin tare da hanyar zuwa don gina sabon daga. Dockerfile image
Dockerfile
Misali, don gina wani image
daga cikin kundin adireshi na yanzu kuma ku sanya masa suna "myimage," zaku iya amfani da umarni mai zuwa: Dockerfile
docker build -t myimage .
Ta amfani da, zaku iya keɓance abubuwan haɗin gwiwa da daidaitawa a cikin wani don biyan takamaiman bukatun aikace-aikacenku. Dockerfile image
Misali, zaku iya amfani da don shigar da fakitin software masu mahimmanci, daidaita muhalli, kwafi lambar tushe da albarkatu cikin. yana ba da hanya mai sassauƙa da sake amfani da ita don ginin da aka keɓance a ciki. Dockerfile image
Dockerfile images
Docker