Compose build+push

This commit is contained in:
Jerome Petazzoni
2016-08-23 14:19:14 -07:00
parent 53ae221632
commit 9f21c7279c
2 changed files with 125 additions and 0 deletions

View File

@@ -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}

View File

@@ -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