Docker compose specifying image vs Dockerfile -
i'm new docker-compose
, after reading docs still have unclear things comes mind.
so far when used docker kept builds in following directory tree:
builds: service a: dockerfile servicea.jar service b: dockerfile serviceb.jar
so when want run use shell script, until read docker-compose
.
i saw there 2 ways of creating , running service (in manner of copying files)
- specifying
build: path/to/my/build/directory
, linkingvolumes:
can see live code , refresh service - specifying
image:
(for examplejava:8
) , usevolumes:
above
what want understand best practice using docker-compose
before dive in it, should create specify image
each service (and replace from
inside dockerfile
) or should specify paths build folders , volumes keep live code changes, , how volumes
work , usages when using image
tag
thanks!
in docker can run services containers , can put state of each service in volume. means you:
- the service run runtime container started image.
- the service's binaries inside image, service writes data volumes.
- the image can either pulled image repository or build on target environment.
- images can build command
docker build
or docker-compose build section.
in example means:
- keep directory structure.
- use docker-compose build section build immages according dockerfiles.
- configure dockerfile put binaries inside image.
- simply start whole stack including build
docker-compose -d
- your binaries changed? replace whole stack
docker-compose --build --force-recreate -d
. command rebuild images , replace containers.
why not place binaries inside volume:
- you lose advantage of image versioning.
- if replace binaries files cannot fallback older image version.
- you can retag images before deploy new version , fallback if error occurs.
- you can tag , save running containers fallback , error investigation.
Comments
Post a Comment