diff --git a/dockercoins/docker-compose.yml-images b/dockercoins/docker-compose.yml-images new file mode 100644 index 00000000..45430660 --- /dev/null +++ b/dockercoins/docker-compose.yml-images @@ -0,0 +1,30 @@ +version: "2" + +services: + rng: + build: rng + image: ${REPOSITORY_SLASH}rng${COLON_TAG} + ports: + - "8001:80" + + hasher: + build: hasher + image: ${REPOSITORY_SLASH}hasher${COLON_TAG} + ports: + - "8002:80" + + webui: + build: webui + image: ${REPOSITORY_SLASH}webui${COLON_TAG} + ports: + - "8000:80" + volumes: + - "./webui/files/:/files/" + + redis: + image: redis + + worker: + build: worker + image: ${REPOSITORY_SLASH}worker${COLON_TAG} + diff --git a/www/htdocs/index.html b/www/htdocs/index.html index 66346b9e..27bc523c 100644 --- a/www/htdocs/index.html +++ b/www/htdocs/index.html @@ -3027,6 +3027,101 @@ Note: the `local` volume driver automatically creates volumes. Note: we could keep the volume around if we wanted. +--- + +# Scripting image building and pushing + +- Earlier, we used some rather crude shell loops to build and push images + +- Compose (and clever environment variables) can help us to make that easier + +- When using Compose file version 2, you can specify *both* `build` and `image`: + +```yaml +version: "2" + +services: + + webapp: + build: src/ + image: jpetazzo/webapp:${TAG} +``` + +Note: Compose tolerates empty (or unset) environment variables, but in this example, +`TAG` *must* be set, because `jpetazzo/webapp:` is not a valid image name. + +--- + +## Updating the Compose file to specify image tags + +- Let's update the Compose file for DockerCoins to make it easier to push it to our registry + +.exercise[ + +- Go back to the `dockercoins` directory: + ```bash + cd ~/orchestration-workshop/dockercoins + ``` + +- Edit `docker-compose.yml`, and update each service to add an `image` directive as follows: + ```yaml + rng: + build: rng + `image: ${REGISTRY_SLASH}rng${COLON_TAG}` + ``` + +] + +You can also directly use the file `docker-compose.yml-images`. + +--- + +## Use the new Compose file + +- We need to set `REGISTRY_SLASH` and `COLON_TAG` variables + +- Then we can use Compose to `build` and `push` + +.exercise[ + +- Set environment variables: + ```bash + export REGISTRY_SLASH=localhost:5000/ + export COLON_TAG=:v0.01 + ``` + +- Build and push with Compose: + ```bash + docker-compose build + docker-compose push + ``` + +] + +--- + +## Why the weird variable names? + +- It would be more intuitive to have: + ```bash + REGISTRY=localhost:5000 + TAG=v0.01 + ``` + +- But then, when the variables are not set, the image names would be invalid + + (they would look like .red[`/rng:`]) + +- Putting the slash and the colon in the variables allows to use the Compose file + even when the variables are not set + +- The variable names (might) remind you that you have to put the trailing slash and heading colon + +--- + +# Docker Application Bundles + + --- # Controlling Docker from a container