For my custom docker php building system I have the following docker-compose
version: "3.7"
services:
base72:
build:
context: .
dockerfile: ./dockerfiles/7.2/Dockerfile
image: myapp/php7.2:$VERSION_PHP_72
stdin_open: true
tty: true
develop72:
build:
context: .
dockerfile: ./dockerfiles/7.2/Dockerfile_develop
links:
- base72
image: myapp/php7.2-dev:$VERSION_PHP_72
volumes:
- "./www:/var/www/html"
nginx:
image: nginx:alpine
ports:
- 7880:7880
links:
- "develop72:develop72"
volumes:
- "./www:/var/www/html"
- "./dist/nginx.conf:/etc/nginx/nginx.conf:ro"
And I build it with the following buildspec.yml
version: 0.2
phases:
install:
runtime-versions:
docker: 18
pre_build:
commands:
- docker login -u $USER -p $TOKEN
build:
commands:
- docker-compose build
post_build:
commands:
- docker-compose up -d
- docker push myapp/php7.2
- docker push myapp/php7.2-dev
Via an .env
file I implement a versioning system method docker images:
VERSION_PHP_72=20191218212112
Each version number is the current date in the format YYYYMMDDHHMMSS
. So I want the version I build from my env file also to be considered the latest. Do you know How I can do that?
2
Answers
For the solution you need the following 2 components:
docker commit
that will allow you to specify a tag to a containerdocker-compose ps -q
That will allow you to get the container is of a specific service.The commands above will be combined into this oneliner:
Where: *
^service^
: The docker-compose service you define indocker-compose.yml
*^image_name^
: The image you want to push into the container as latest.So in order to push the
myapp/php7.2-dev
you will need to run:Therefore the end
codebuild.yml
will be:docker tag
can assign a tag to an existing image. I would highly recommend also pushing the timestamped version of your image, so that it’s easy to deploy a known-good version and to roll back later if things don’t go well. (This is also very important in Kubernetes.)I’d try a sequence like this: