Ko te whakamaoritanga o te whakamaoritanga podcast kua whakaritea i mua i te tiimata o te akoranga
He taputapu whakamiharo a Docker Compose mo te hanga mahi
taiao mo te puranga i whakamahia i roto i to tono. Ka taea e koe te tautuhi
ia wahanga o to tono, e whai ana i te wetereo marama me te ngawari ki roto
kōnae
Tuhinga o mua
kāhui
Engari ko te tikanga ka taea e koe te whakamahi i te konae tito-docker ano ki roto
te tukanga whanaketanga me te taiao whakaputa? Ka whakamahi ranei i te konae ano mo
whakaari? Ae, i te nuinga o te waa, ae, engari mo tenei mahi e hiahia ana matou ki nga mea e whai ake nei:
- Taurangi taurangi: te whakamahi taurangi taiao mo etahi
nga uara ka huri i ia taiao. - Whakakore whirihoranga: te kaha ki te tautuhi i te tuarua (me etahi atu
tetahi atu) docker-compose file ka huri i tetahi mea mo
tuatahi, ma te tito docker e whakahaere te whakakotahi i nga konae e rua.
Nga rereketanga i waenga i te whanaketanga me nga konae whakaputa
I te wa o te whanaketanga, ka hiahia pea koe ki te tirotiro i nga huringa waehere
wā tūturu. Hei mahi i tenei, ko te nuinga o te waa ka whakauruhia te rōrahi me te waehere puna
ipu kei roto te wa whakahaere mo to tono. Engari mo te taiao whakaputa
Kaore e pai ana tenei tikanga.
I roto i te whakaputanga, he kahui koe me te maha o nga pona, a ko te rōrahi he rohe
e pa ana ki te pona kei te whakahaere to ipu (ranei ratonga), no reira kare koe
ka taea e koe te whakairi i te waehere puna me te kore he mahi uaua kei roto
tukutahi waehere, tohu, etc.
Engari, i te nuinga o te wa ka hiahia matou ki te hanga whakaahua me tetahi putanga motuhake o to waehere.
He tikanga ki te tohu ki te tohu e tika ana (ka taea e koe te whakamahi semantic
putanga, tetahi atu punaha ranei i runga i to whakaaro).
Whakawhiti Whirihoranga
I runga i nga rereketanga me te rereke pea o to whakawhirinakitanga i roto i nga ahuatanga
te whanaketanga me te whakaputanga, e marama ana ka hiahia tatou i nga konae whirihoranga rereke.
E tautoko ana te tito Docker ki te hanumi i nga konae tito rereke ki
whiwhi i te whirihoranga whakamutunga. Me pehea te mahi ka kitea i roto i te tauira:
$ cat docker-compose.yml
version: "3.2"
services:
whale:
image: docker/whalesay
command: ["cowsay", "hello!"]
$ docker-compose up
Creating network "composeconfigs_default" with the default driver
Starting composeconfigs_whale_1
Attaching to composeconfigs_whale_1
whale_1 | ________
whale_1 | < hello! >
whale_1 | --------
whale_1 |
whale_1 |
whale_1 |
whale_1 | ## .
whale_1 | ## ## ## ==
whale_1 | ## ## ## ## ===
whale_1 | /""""""""""""""""___/ ===
whale_1 | ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
whale_1 | ______ o __/
whale_1 | __/
whale_1 | __________/
composeconfigs_whale_1 exited with code 0
Ka rite ki te korero, kei te tautoko te tito docker ki te whakakotahi i nga tito maha -
kōnae, ka taea e koe te whakakore i nga momo tawhā i te konae tuarua. Hei tauira:
$ cat docker-compose.second.yml
version: "3.2"
services:
whale:
command: ["cowsay", "bye!"]
$ docker-compose -f docker-compose.yml -f docker-compose.second.yml up
Creating composeconfigs_whale_1
Attaching to composeconfigs_whale_1
whale_1 | ______
whale_1 | < bye! >
whale_1 | ------
whale_1 |
whale_1 |
whale_1 |
whale_1 | ## .
whale_1 | ## ## ## ==
whale_1 | ## ## ## ## ===
whale_1 | /""""""""""""""""___/ ===
whale_1 | ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
whale_1 | ______ o __/
whale_1 | __/
whale_1 | __________/
composeconfigs_whale_1 exited with code 0
Ko tenei wetereo kaore i te tino watea i te wa o te whanaketanga, i te wa o te whakahau
me mahi maha nga wa.
Waimarie, ko te tito docker ka rapu aunoa mo tetahi konae motuhake e kiia ana
docker-compose.override.yml ki te whakakore i nga uara docker-compose.yml. Mena
whakaingoa ano te konae tuarua, ka whiwhi koe i te hua ano, ma te whakamahi i te whakahau taketake:
$ mv docker-compose.second.yml docker-compose.override.yml
$ docker-compose up
Starting composeconfigs_whale_1
Attaching to composeconfigs_whale_1
whale_1 | ______
whale_1 | < bye! >
whale_1 | ------
whale_1 |
whale_1 |
whale_1 |
whale_1 | ## .
whale_1 | ## ## ## ==
whale_1 | ## ## ## ## ===
whale_1 | /""""""""""""""""___/ ===
whale_1 | ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
whale_1 | ______ o __/
whale_1 | __/
whale_1 | __________/
composeconfigs_whale_1 exited with code 0
Kaati, he maamaa ake te mahara.
Te wawaotanga o nga Taurangi
Tautoko kōnae whirihoranga
taurangi
services:
my-service:
build:
context: .
image: private.registry.mine/my-stack/my-service:${MY_SERVICE_VERSION:-latest}
...
A ki te mahi koe hanga hanga (pea ranei) docker-compose kaore he taurangi taiao
$MY_SERVICE_VERSION, ka whakamahia te uara houengari ki te whakaturia e koe
te uara o te taurangi taiao i mua i te hanga, ka whakamahia i te wa e hanga ana, e pana ana ranei
ki te rehita private.registry.mine.
Ko aku tikanga
Ko nga huarahi e pai ana ki a au ka whai hua ano ki a koe. Ka whai ahau i enei
ture ngawari:
- Ko aku puranga katoa mo te hanga, te whanaketanga (me etahi atu taiao ranei) kua tautuhia ma
docker-tito kōnae - Ko nga konae whirihoranga e tika ana kia kapi katoa aku taiao, ka taea
karo i te tāruarua. - Me kotahi te whakahau ngawari ki te mahi i ia taiao.
- Ko te whirihoranga matua kua tautuhia i roto i te konae docker-compose.yml.
- Ka whakamahia nga taurangi taiao hei tautuhi i nga tohu whakaahua, etahi atu ranei
nga taurangi ka rereke pea mai i te taiao ki te taiao (te whakaari, te whakauru,
hanga). - Ko nga uara o nga taurangi whakaputa ka whakamahia hei uara mo
ma te taunoa, ka whakaitihia nga tupono mena ka whakarewahia te puranga ki te whakaputa kore
tautuhi taurangi taiao. - Hei timata i tetahi ratonga i roto i te taiao whakaputa, whakamahia te whakahau toha tapae kaipahua - tito-kōnae docker-compose.yml -me-rehita-auth taku-tapae-ingoa.
- Ka timata te taiao mahi ki te whakamahi i te whakahau te tautuhi-te hanga -d.
Ka titiro tatou ki tetahi tauira ngawari.
# docker-compose.yml
...
services:
my-service:
build:
context: .
image: private.registry.mine/my-stack/my-service:${MY_SERVICE_VERSION:-latest}
environment:
API_ENDPOINT: ${API_ENDPOINT:-https://production.my-api.com}
...
И
# docker-compose.override.yml
...
services:
my-service:
ports: # This is needed for development!
- 80:80
environment:
API_ENDPOINT: https://devel.my-api.com
volumes:
- ./:/project/src
...
Ka taea e au te whakamahi docker-compose (docker-compose up)ki te whakahaere i te puranga ki roto
aratau whanaketanga me te waehere puna kua whakauruhia ki roto /kaupapa/src.
Ka taea e au te whakamahi i enei konae ano ki te hanga! A ka taea e au te whakamahi
taua kōnae docker-compose.yml mo te whakaari. Hei whakawhānui ake i tenei ki
production, Me tika ahau ki te hanga me te tuku i te whakapakoko ki te tohu tautuhia kē
i te wahanga CI:
export MY_SERVICE_VERSION=1.2.3
docker-compose -f docker-compose.yml build
docker-compose -f docker-compose.yml push
I roto i te hanga, ka taea te whakahaere ma te whakamahi i nga whakahau e whai ake nei:
export MY_SERVICE_VERSION=1.2.3
docker stack deploy my-stack --compose-file docker-compose.yml --with-registry-auth
A, ki te hiahia koe ki te mahi pera i runga i te atamira, me tautuhi koe
nga huringa taiao e tika ana mo te mahi i roto i te taiao whakaari:
export MY_SERVICE_VERSION=1.2.3
export API_ENDPOINT=http://staging.my-api.com
docker stack deploy my-stack --compose-file docker-compose.yml --with-registry-auth
Ko te mutunga mai, i whakamahia e matou nga konae tito docker e rua, kaore he
Ka taea te whakamahi i nga whirihoranga taarua mo tetahi taiao kei a koe!
Ako atu mo te akoranga
Source: will.com