paint-brush
Hagaajinta Sawirrada Docker waa in ka badan hal iyo wax la sameeyayby@aleksandrov
Taariikh cusub

Hagaajinta Sawirrada Docker waa in ka badan hal iyo wax la sameeyay

by Igor Alexandrov17m2025/01/30
Read on Terminal Reader

Aad u dheer; In la akhriyo

Maqaalkani waa qayb ka mid ah qoraallo taxane ah halkaas oo aan ku dhex mari doono khad kasta oo Dockerfile ah oo aan ku sharaxi doono hababka ugu fiican iyo hagaajinta. Maqaalka ugu horreeya wuxuu taaban doonaa kaliya hagaajinta dhimista cabbirka sawirka.
featured image - Hagaajinta Sawirrada Docker waa in ka badan hal iyo wax la sameeyay
Igor Alexandrov HackerNoon profile picture
0-item


Maqaalkani waa qayb ka mid ah qoraallo taxane ah oo aan ku dhex mari doono khad kasta oo ka mid ah Rails default Dockerfile oo aan sharxi doono hababka ugu fiican iyo hagaajinta.


Sawirada docker waxaa loo hagaajin karaa siyaabo kala duwan oo ay ku jiraan, laakiin aan ku xaddidnayn, dhimista cabbirka sawirka, dhisidda tayaynta, amniga, iyo ilaalinta hababka ugu wanaagsan, iyo hagaajinta gaarka ah ee codsiga. Maqaalka koowaad, waxaan taaban doonaa oo kaliya hagaajinta dhimista cabbirka sawirka waxaanan sharxi doonaa sababta ay muhiim u yihiin.

Waa maxay sababta loo hagaajiyo cabbirka sawirka?

Sida geeddi-socod kasta oo kale ee horumarinta software, horumariye kasta ayaa liis gareyn doona sababaha uu u doonayo inuu ka dhigo Docker-kiisa si dhakhso leh u dhismo. Waxaan tixi doonaa sababaha iigu muhiimsan.

Dhismayaasha dhaqsaha badan & hawlgalinta

Sawirada yaryar ayaa si degdeg ah u dhismaya sababtoo ah faylal iyo lakabyo yar ayaa u baahan in la habeeyo. Tani waxay wanaajisaa wax soo saarka horumariyaha, gaar ahaan inta lagu jiro wareegyada horumarka soo noqnoqda. Sawirada yaryar waxay qaataan wakhti yar in lagu riixo diiwaanka oo laga soo jiido inta lagu jiro hawlgalinta. Tani waxay si gaar ah muhiim ugu tahay dhuumaha CI/CD halkaasoo weelasha la dhisay oo inta badan la geeyo.

Kharashyada kaydinta oo la dhimay & isticmaalka balaastigga shabakadda

Sawirada yaryar waxay cunaan kayd yar oo lagu kaydiyo diiwaanada weelka, mishiinada horumarinta deegaanka, iyo adeegayaasha wax soo saarka. Tani waxay yaraynaysaa kharashaadka kaabayaasha, gaar ahaan hawlgalinta baaxadda leh. Sawirada yaryar waxay isticmaalaan xajmigoodu yar yahay marka loo kala wareejiyo server-yada, gaar ahaan muhiim markaad dhisayso sawirada gudaha ama dhuumaha CI/CD oo aad ku riixayso diiwaanka.


"Waxaan ku kharash gareynay $3.2m daruurta sanadka 2022... Waxaan u taagannahay inaan badbaadino qiyaastii $7m kharashaadka server-ka muddo shan sano ah ka bixista daruurteena." David Heinemeier Hansson - HEY World

Waxqabadka iyo amniga oo la hagaajiyay

Sawirada yaryar waxay u baahan yihiin ilo yar (tusaale, CPU, RAM) si ay u rartaan oo ay u ordaan, taasoo hagaajinaysa waxqabadka guud ee codsiyada weelka lagu shubay. Waqtiyada bilawga ah ee dhaqsaha badan waxay la macno tahay in adeegyadaagu ay si dhakhso ah u diyaarsan yihiin, taas oo muhiim u ah cabirida iyo nidaamyada helitaan sare. Sawirada ugu yar sida alpine ama debian-slim waxaa ku jira baakado yar oo horay loo sii rakibay, taas oo yaraynaysa khatarta ah in software aan la daboolin ama aan loo baahnayn laga faa'iidaysto.


Wax kasta oo aan kor ku soo sheegnay ka sokow, ka saarista faylasha iyo qalabka aan loo baahnayn waxay yaraynaysaa carqaladaha marka la ogaanayo arrimaha waxayna keenaysaa ilaalin wanaagsan iyo hoos u dhigista deynta farsamada.

Kormeerka sawirada Docker

Si aad u hesho cabbirro kala duwan oo sawirka ah, oo ay ku jiraan cabbirka, waxaad sidoo kale eegi kartaa Desktop-ka Docker ama waxaad ku socodsiin kartaa amarka docker images ee terminalka.


 ➜ docker images REPOSITORY TAG IMAGE ID CREATED SIZE kamal-dashboard latest 673737b771cd 2 days ago 619MB kamal-proxy latest 5f6cd8983746 6 weeks ago 115MB docs-server latest a810244e3d88 6 weeks ago 1.18GB busybox latest 63cd0d5fb10d 3 months ago 4.04MB postgres latest 6c9aa6ecd71d 3 months ago 456MB postgres 16.4 ced3ad69d60c 3 months ago 453MB


Ogaanshaha cabbirka sawirka kuma siinayso sawir buuxa. Ma garanaysid waxa ku jira sawirka, inta lakab ee uu leeyahay, ama inta lakab kasta uu le'eg yahay. Lakabka sawirka Docker waa lakabka nidaamka faylka wax akhriya-kaliya, kaas oo ah qayb ka mid ah sawirka Docker. Lakab kastaa wuxuu u taagan yahay isbeddelo lagu sameeyay nidaamka faylka sawirka, sida ku darista faylalka, habaynta wax ka beddelka, ama rakibidda software.


Sawirada docker-ka waxaa loo dhisay si kordheysa, lakab lakab, lakab walbana wuxuu u dhigmaa tilmaamaha ku jira Dockerfile . Si aad u hesho lakabyada sawirka, waxaad socodsiin kartaa amarka docker history .


 ➜ docker history kamal-dashboard:latest IMAGE CREATED CREATED BY SIZE COMMENT 673737b771cd 4 days ago CMD ["./bin/thrust" "./bin/rails" "server"] 0B buildkit.dockerfile.v0 <missing> 4 days ago EXPOSE map[80/tcp:{}] 0B buildkit.dockerfile.v0 <missing> 4 days ago ENTRYPOINT ["/rails/bin/docker-entrypoint"] 0B buildkit.dockerfile.v0 <missing> 4 days ago USER 1000:1000 0B buildkit.dockerfile.v0 <missing> 4 days ago RUN /bin/sh -c groupadd --system --gid 1000 … 54MB buildkit.dockerfile.v0 <missing> 4 days ago COPY /rails /rails # buildkit 56.2MB buildkit.dockerfile.v0 <missing> 4 days ago COPY /usr/local/bundle /usr/local/bundle # b… 153MB buildkit.dockerfile.v0 <missing> 4 days ago ENV RAILS_ENV=production BUNDLE_DEPLOYMENT=1… 0B buildkit.dockerfile.v0 <missing> 4 days ago RUN /bin/sh -c apt-get update -qq && apt… 137MB buildkit.dockerfile.v0 <missing> 4 days ago WORKDIR /rails 0B buildkit.dockerfile.v0 <missing> 3 weeks ago CMD ["irb"] 0B buildkit.dockerfile.v0 <missing> 3 weeks ago RUN /bin/sh -c set -eux; mkdir "$GEM_HOME";… 0B buildkit.dockerfile.v0 <missing> 3 weeks ago ENV PATH=/usr/local/bundle/bin:/usr/local/sb… 0B buildkit.dockerfile.v0 <missing> 3 weeks ago ENV BUNDLE_SILENCE_ROOT_WARNING=1 BUNDLE_APP… 0B buildkit.dockerfile.v0 <missing> 3 weeks ago ENV GEM_HOME=/usr/local/bundle 0B buildkit.dockerfile.v0 <missing> 3 weeks ago RUN /bin/sh -c set -eux; savedAptMark="$(a… 78.1MB buildkit.dockerfile.v0 <missing> 3 weeks ago ENV RUBY_DOWNLOAD_SHA256=018d59ffb52be3c0a6d… 0B buildkit.dockerfile.v0 <missing> 3 weeks ago ENV RUBY_DOWNLOAD_URL=https://cache.ruby-lan… 0B buildkit.dockerfile.v0 <missing> 3 weeks ago ENV RUBY_VERSION=3.4.1 0B buildkit.dockerfile.v0 <missing> 3 weeks ago ENV LANG=C.UTF-8 0B buildkit.dockerfile.v0 <missing> 3 weeks ago RUN /bin/sh -c set -eux; mkdir -p /usr/loca… 19B buildkit.dockerfile.v0 <missing> 3 weeks ago RUN /bin/sh -c set -eux; apt-get update; a… 43.9MB buildkit.dockerfile.v0 <missing> 3 weeks ago # debian.sh --arch 'arm64' out/ 'bookworm' '… 97.2MB debuerreotype 0.15


Maadaama aan horay u bixiyay aragti ku saabsan sawirada, iyo lakabyada, waa waqtigii la sahamin lahaa Dockerfile . Laga bilaabo Rails 7.1, Dockerfile waxaa lagu soo saaray arjiga cusub ee Rails-ka. Hoos waxaa ku yaal tusaale sida uu u ekaan karo.


 # syntax=docker/dockerfile:1 # check=error=true # Make sure RUBY_VERSION matches the Ruby version in .ruby-version ARG RUBY_VERSION=3.4.1 FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base # Rails app lives here WORKDIR /rails # Install base packages # Replace libpq-dev with sqlite3 if using SQLite, or libmysqlclient-dev if using MySQL RUN apt-get update -qq && \ apt-get install --no-install-recommends -y curl libjemalloc2 libvips libpq-dev && \ rm -rf /var/lib/apt/lists /var/cache/apt/archives # Set production environment ENV RAILS_ENV="production" \ BUNDLE_DEPLOYMENT="1" \ BUNDLE_PATH="/usr/local/bundle" \ BUNDLE_WITHOUT="development" # Throw-away build stage to reduce size of final image FROM base AS build # Install packages needed to build gems RUN apt-get update -qq && \ apt-get install --no-install-recommends -y build-essential curl git pkg-config libyaml-dev && \ rm -rf /var/lib/apt/lists /var/cache/apt/archives # Install application gems COPY Gemfile Gemfile.lock ./ RUN bundle install && \ rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \ bundle exec bootsnap precompile --gemfile # Copy application code COPY . . # Precompile bootsnap code for faster boot times RUN bundle exec bootsnap precompile app/ lib/ # Precompiling assets for production without requiring secret RAILS_MASTER_KEY RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile # Final stage for app image FROM base # Copy built artifacts: gems, application COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}" COPY --from=build /rails /rails # Run and own only the runtime files as a non-root user for security RUN groupadd --system --gid 1000 rails && \ useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \ chown -R rails:rails db log storage tmp USER 1000:1000 # Entrypoint prepares the database. ENTRYPOINT ["/rails/bin/docker-entrypoint"] # Start server via Thruster by default, this can be overwritten at runtime EXPOSE 80 CMD ["./bin/thrust", "./bin/rails", "server"]


Hoos waxaan ku siin doonaa liiska hababka iyo xeerarka marka lagu dabaqo Dockerfile ee kore si cabbirka sawirka ugu dambeeya looga dhigo mid hufan.

Kordhi xirmooyinka xirmooyinka

Waxaan hubaa inaad ku hayso kaliya software-ka loo baahan yahay mashiinka horumarinta deegaankaaga. Isla sidaas oo kale waa in lagu dabaqaa sawirada Docker. Tusaalooyinka hoose waxaan si joogto ah uga sii dari doonaa Dockerfile-ka laga soo saaray Rails Dockerfile-ka sare. Waxaan u tixraaci doonaa inuu yahay nooca Dockerfile asalka ah .

Xeerka #1: Isticmaal sawirada salka ugu yar

 FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base


Sawirka salku waa barta laga bilaabo Dockerfile . Waa sawirka loo isticmaalo in lagu abuuro weelka. Sawirka salku waa lakabka koowaad ee Dockerfile , waana lakabka kaliya ee aan abuurmin Dockerfile laftiisa.


Sawirka salka waxaa lagu qeexay amarka FROM , oo ay ku xigto magaca sawirka iyo summada. Calaamaddu waa ikhtiyaari, haddii aan la cayimin, summada latest ayaa la isticmaalaa. Sawirka salku wuxuu noqon karaa sawir kasta oo laga heli karo Docker Hub ama diiwaan kasta oo kale.


Dockerfile ku saabsan, waxaan isticmaaleynaa sawirka ruby ee leh sumadda 3.4.1-slim . Sawirka ruby waa sawirka rasmiga ah ee Ruby ee laga heli karo Docker Hub. 3.4.1-slim tag waa nooc caato ah oo ka mid ah sawirka Ruby kaas oo ku salaysan sawirka debian-slim . Halka sawirka debian-slim uu yahay nooca ugu yar ee muuqaalka Debian Linux kaas oo loo habeeyay cabbirka. Fiiri shaxda hoose si aad fikrad uga hesho sida uu u yar yahay sawirka slim ah.


 ➜ docker images --filter "reference=ruby" REPOSITORY TAG IMAGE ID CREATED SIZE ruby 3.4.1-slim 0bf957e453fd 5 days ago 219MB ruby 3.4.1-alpine cf9b1b8d4a0c 5 days ago 99.1MB ruby 3.4.1-bookworm 1e77081540c0 5 days ago 1.01GB


Laga bilaabo Janaayo, 2024, siidaynta Debian hadda waxa loo yaqaan bookworm kii horena waa bullseye .


219 MB halkii 1GB - farqi weyn. Laakiin maxaa dhacaya haddii sawirka alpine uu xitaa ka yar yahay? Sawirka alpine wuxuu ku salaysan yahay qaybinta Alpine Linux, kaas oo ah qaybinta Linux aad u khafiif ah kaas oo loo habeeyay cabbirka iyo amniga. Alpine waxay isticmaashaa maktabadda musl (halkii glibc ) iyo busybox (isku-dhafka utility Unix) halkii ay ka isticmaali lahaayeen dhiggooda GNU. Inkasta oo ay farsamo ahaan suurtogal tahay in la isticmaalo sawirka alpine si loo socodsiiyo Rails, kuma dabooli doono maqaalkan.

Xeerka #2: Yaree lakabyada

 RUN apt-get update -qq && \ apt-get install --no-install-recommends -y curl libjemalloc2 libvips libpq-dev && \ rm -rf /var/lib/apt/lists /var/cache/apt/archives


RUN kasta, COPY iyo FROM tilmaamaha Dockerfile wuxuu abuuraa lakab cusub. Lakabyada badan ee aad leedahay, ayaa weynaanta cabbirka sawirka. Tani waa sababta habka ugu fiicani uu yahay in la isku daro amaro kala duwan oo lagu daro hal tilmaamo RUN . Si aan qodobkan u qeexno, aan eegno tusaalaha hoose.


 # syntax=docker/dockerfile:1 # check=error=true # Make sure RUBY_VERSION matches the Ruby version in .ruby-version ARG RUBY_VERSION=3.4.1 FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base RUN apt-get update -qq RUN apt-get install --no-install-recommends -y curl RUN apt-get install --no-install-recommends -y libjemalloc2 RUN apt-get install --no-install-recommends -y libvips RUN apt-get install --no-install-recommends -y libpq-dev RUN rm -rf /var/lib/apt/lists /var/cache/apt/archives CMD ["echo", "Whalecome!"]


Waxaan u kala qaybiyay tilmaanta RUN dhowr sadar, taas oo sida iska cad ka dhigaysa mid aadamigu akhrin karo . Laakiin sidee ayay u saameyn doontaa cabbirka sawirka? Aan dhisno sawirka oo aan iska hubinno.


 ➜ time docker build -t no-minimize-layers --no-cache -f no-minimize-layers.dockerfile . 0.31s user 0.28s system 2% cpu 28.577 total


Waxay qaadatay 28 ilbiriqsi si loo dhiso sawirka, halka in la dhiso nooca asalka ah ee lakabyada la yareeyay waxay qaadanaysaa 19 ilbiriqsi oo keliya ( ku dhawaad 33% dhakhso ah ).


 ➜ time docker build -t original --no-cache -f original.dockerfile . 0.25s user 0.28s system 2% cpu 19.909 total


Aynu eegno xajmiga sawirada


 ➜ docker images --filter "reference=*original*" --filter "reference=*no-minimize*" REPOSITORY TAG IMAGE ID CREATED SIZE original latest f1363df79c8a 8 seconds ago 356MB no-minimize-layers latest ad3945c8a8ee 43 seconds ago 379MB


Sawirka leh lakabyada la yareeyey ayaa 23 MB ka yar kan aan lahayn lakabyo la yareeyey. Tani waa dhimista 6% ee cabbirka . In kasta oo ay u muuqato farqi yar oo tusaalahan ah, farqigu aad ayuu u weynaan doonaa haddii aad u kala qaybiso dhammaan tilmaamaha RUN dhowr xariiq.

Xeerka #3: Ku rakib kaliya waxa loo baahan yahay

Sida caadiga ah, apt-get install wuxuu ku rakibaa baakadaha lagu taliyay iyo sidoo kale xirmooyinka aad weydiisay in lagu rakibo. Xulashada --no-install-recommends waxay u sheegaysaa apt-get in lagu rakibo kaliya baakooyinka si cad loo cayimay oo aan ahayn kuwa lagu taliyay.


 ➜ time docker build -t without-no-install-recommends --no-cache -f without-no-install-recommends.dockerfile . 0.33s user 0.30s system 2% cpu 29.786 total ➜ docker images --filter "reference=*original*" --filter "reference=*recommends*" REPOSITORY TAG IMAGE ID CREATED SIZE without-no-install-recommends latest 41e6e37f1e2b 3 minutes ago 426MB minimize-layers latest dff22c85d84c 17 minutes ago 356MB


Sida aad arki karto, sawirka aan lahayn --no-install-recommends ayaa 70 MB ka weyn kan asalka ah . Tani waa korodhka 16% ee cabbirka .


Isticmaal utility quusin si aad u aragto faylasha lagu daray sawirka - wax badan ka sii akhri dhammaadka maqaalka.

Xeerka # 4: Nadiifi ka dib rakibidda

Dockerfile ka asalka ah waxaa ka mid ah rm -rf /var/lib/apt/lists/* /var/cache/apt/archives Command ka dib amarka apt-get install . Amarkani waxa uu meesha ka saarayaa liisaska baakooyinka iyo kaydadka aan hadda loo baahnayn rakibidda ka dib. Aynu aragno sida ay u saameynayso cabbirka sawirka, si loo gaaro taas, waxaan abuuri doonaa Dockerfile cusub iyada oo aan lahayn amarka nadiifinta .


 RUN apt-get update -qq && \ apt-get install --no-install-recommends -y curl libjemalloc2 libvips libpq-dev


Dhisidda sawiradu waxay qaadataa waqti isku mid ah tan asalka ah, taas oo macno samaynaysa.


 ➜ time docker build -t without-cleaning --no-cache -f without-cleaning.dockerfile . 0.28s user 0.30s system 2% cpu 21.658 total


Aynu eegno xajmiga sawirada


 ➜ docker images --filter "reference=*original*" --filter "reference=*cleaning*" REPOSITORY TAG IMAGE ID CREATED SIZE without-cleaning latest 52884fe50773 2 minutes ago 375MB original latest f1363df79c8a 16 minutes ago 356MB


Sawirka aan nadiifinta lahayn ayaa 19 MB ka weyn kan nadiifinta leh, tani waa korodhka 5% ee cabbirka .

Xaaladda ugu xun

Maxaa dhacaya haddii dhammaan afarta hagaajin ee kor lagu soo sheegay aan la dabaqin? Aan abuurno Dockerfile cusub anagoon wax hagaajin ah samayno oo aan dhisno sawirka.


 # syntax=docker/dockerfile:1 # check=error=true ARG RUBY_VERSION=3.4.1 FROM docker.io/library/ruby:$RUBY_VERSION AS base RUN apt-get update -qq RUN apt-get install -y curl RUN apt-get install -y libjemalloc2 RUN apt-get install -y libvips RUN apt-get install -y libpq-dev CMD ["echo", "Whalecome!"]


 ➜ time docker build -t without-optimizations --no-cache -f without-optimizations.dockerfile . 0.46s user 0.45s system 1% cpu 1:02.21 total


Wow, waxay qaadatay in ka badan hal daqiiqo in la dhiso sawirka.


 ➜ docker images --filter "reference=*original*" --filter "reference=*without-optimizations*" REPOSITORY TAG IMAGE ID CREATED SIZE without-optimizations latest 45671929c8e4 2 minutes ago 1.07GB original latest f1363df79c8a 27 hours ago 356MB


Sawirka iyada oo aan la hagaajinin ayaa 714 MB ka weyn kii asalka ahaa, tani waa 200% korodhka cabbirka . Tani waxay si cad u muujineysaa sida ay muhiimka u tahay in la hagaajiyo Dockerfile , sawirada waaweyn waxay qaataan waqti badan si ay u dhisaan oo ay u isticmaalaan meelo badan oo disk ah.

Had iyo jeer isticmaal .dockerignore

Faylka .dockerignore wuxuu la mid yahay faylka .gitignore ee uu isticmaalo Git. Waxaa loo istcimaalaa in laga saaro faylalka iyo hagayaasha laga soo bilaabo macnaha guud ee dhismaha. Macnuhu waa qaabka faylalka iyo hagayaasha loo diro Docker daemon marka sawir la dhisayo. Macnaha guud waxaa loo diraa Docker daemon sidii daamur ahaan, marka waa muhiim in aad u yareyso sida ugu macquulsan.


Haddii, sabab kastaba ha ahaatee, aadan haysan faylka .dockerignore ee mashruucaaga, waxaad u abuuri kartaa gacanta. Waxaan kuu soo jeedinayaa inaad isticmaasho qaabka rasmiga ah ee Rails .dockerignore qaab bilow ahaan. Hoos waxaa ku yaal tusaale sida uu u ekaan karo.


 # See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files. # Ignore git directory. /.git/ /.gitignore # Ignore bundler config. /.bundle # Ignore all environment files. /.env* # Ignore all default key files. /config/master.key /config/credentials/*.key # Ignore all logfiles and tempfiles. /log/* /tmp/* !/log/.keep !/tmp/.keep # Ignore pidfiles, but keep the directory. /tmp/pids/* !/tmp/pids/.keep # Ignore storage (uploaded files in development and any SQLite databases). /storage/* !/storage/.keep /tmp/storage/* !/tmp/storage/.keep # Ignore assets. /node_modules/ /app/assets/builds/* !/app/assets/builds/.keep /public/assets # Ignore CI service files. /.github # Ignore development files /.devcontainer # Ignore Docker-related files /.dockerignore /Dockerfile*


Haysashada faylka .dockerfile ee mashruuca kaliya ma ogola in laga reebo faylasha iyo hagayaasha aan loo baahnayn (tusaale, GitHub workflows ka .github folder ama JavaScript ku tiirsanaanta ka node_modules ) ka macnaha guud. Waxa kale oo ay kaa caawinaysaa in laga fogaado in si lama filaan ah loogu daro macluumaadka xasaasiga ah ee sawirka. Tusaale ahaan, faylka .env ee ka kooban doorsoomayaasha deegaanka ama faylka master.key ee loo isticmaalo in lagu furfuro aqoonsiga.

Isticmaal quusi

Dhammaan hagaajinta kor ku xusan waxay u muuqan karaan kuwo muuqda marka la sharraxo. Maxaa la sameeyaa haddii aad hore u leedahay muuqaal weyn, oo aanad garanayn meel aad ka bilowdo?


Qalabka aan ugu jeclahay uguna faa'iido badan waa quusitaanka . Quustu waa aalad TUI ah oo lagu sahamiyo sawirka Docker, waxa ku jira lakabka, iyo ogaanshaha siyaabaha lagu dhimo cabbirka sawirka. Quusidda waxaa lagu rakibi karaa maamulaha xirmada nidaamkaaga, ama waxaad isticmaali kartaa sawirkeeda rasmiga ah ee Docker si aad u socodsiiso. Aan isticmaalno sawirka laga soo qaatay xaaladeena ugu xun.


 docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock wagoodman/dive:latest without-optimizations 


Qalabka kormeerida lakabyada Docker

Sawirka kore, waxaad ka arki kartaa kormeerka sawirkayaga ugu aan fiicneyn. Quustu waxay tusinaysaa cabbirka lakab kasta, wadarta cabbirka sawirka, iyo faylalka la beddelay (ku daray, wax laga beddelay, ama la tirtiray) lakab kasta. Aniga ahaan, tani waa habka ugu faa'iido badan ee Quusidda. Adigoo taxaya faylasha ku jira guddiga saxda ah, waxaad si fudud u aqoonsan kartaa faylasha aan loo baahnayn oo aad ka saari kartaa amarrada ku dara sawirka.


Hal shay oo aan runtii ka jeclahay Dive ayaa ah, ka sokow haysashada UI terminal, waxay sidoo kale bixin kartaa wax soo saarka CI-saaxiibtinimo, kaas oo sidoo kale waxtar u yeelan kara horumarka maxalliga ah sidoo kale. Si aad u isticmaasho, ku soco Dive oo leh doorsoomiyaha deegaanka ee CI oo loo dhigay true , soosaarka amarku wuxuu ku yaalaa shaashadda hoose.


 docker run -e CI=true --rm -it -v /var/run/docker.sock:/var/run/docker.sock wagoodman/dive:latest without-optimizations 


Quus wax soo saarka CI-saaxiibtinimo

Dookhayga shakhsi ahaaneed waa in aan isticmaalo Quus jadwalaysan, tusaale ahaan, todobaadkiiba hal mar, si loo hubiyo in sawiradaadu ay wali qaab fiican yihiin. Maqaallada soo socda, waxaan dabooli doonaa socodka shaqada otomaatiga ah ee aan isticmaalo si aan u hubiyo Dockerfile-kayga, oo ay ku jiraan quusi iyo Hadolint .

Ha xoqin lakabyada

Mid ka mid ah hab lagu yareeyo cabbirka sawirka oo aan arkay waa in la isku dayo in la xoqo lakabyada. Fikradda waxay ahayd in la isku daro dhowr lakab oo hal lakab ah si loo yareeyo cabbirka sawirka. Docker wuxuu lahaa ikhtiyaar tijaabo ah --squash , ka sokow, waxaa jiray qalab dhinac saddexaad ah sida docker-squash .


In kasta oo habkani uu shaqaynayey wakhti hore, hadda waa la tirtiray oo laguma talinayo in la isticmaalo. Lakabyada squashing waxay burburiyeen astaanta aasaasiga ah ee Docker ee kaydinta lakabka. Marka laga reebo taas, markaad isticmaalayso --squash waxaad si lama filaan ah ugu dari kartaa faylalka xasaasiga ah ama ku meel gaarka ah ee lakabyada hore sawirka ugu dambeeya. Tani waa hab-dhammaan-ama-waxba oo ka maqan xakamaynta-gacan.


Halkii la isku xoqin lahaa lakabyada, waxaa lagu talinayaa in la isticmaalo dhismooyin heerar badan ah. Rails Dockerfile waxay horeyba u isticmaashaa dhismooyin heerar badan ah, waxaan ku sharixi doonaa sida ay u shaqeyso maqaalka soo socda.

Gabagabadii

Hagaajinta sawirada Docker, sida wanaajinta kale, lama samayn karo hal mar oo la iloobo . Waa hawl socota oo u baahan hubin iyo hagaajin joogto ah. Waxaan isku dayay inaan daboolo aasaaska, laakiin waxay muhiim u yihiin in la ogaado oo la fahmo. Maqaallada soo socda, waxaan ku dabooli doonaa farsamooyin iyo qalab aad u horumarsan oo kaa caawin kara in Docker-kaaga uu si dhakhso leh oo hufan u dhiso.