Commit d6e31b6b authored by Adam Hawkins's avatar Adam Hawkins

Update docker cp example

parent 3a00090e
......@@ -90,27 +90,26 @@ container. Next `docker cp` specifies the `container:path` and copies
that to `something.jar`. No permissions or anything to worry about.
Finally the container is stopped and removed.
Here is another example from this blog's [source][]. The example uses
`docker create`, and `docker start` to prepare a container, then
`docker cp` to copy an entire directory.
Here is another example from [Docker & Node boilerplate][node]. The
example uses `docker create` and `docker cp` to prepare a container
for installing node.js dependencies from `package.json`.
`package.json` is copied into the container, the container runs, then
`node_modules` is copied out, finally the container is stopped and
removed.
```Makefile
.PHONY: dist
dist: $(DOCKER_IMAGE)
mkdir -p dist tmp
docker create -i $(BUILD_ENV) slashdeploy/blog \
bundle exec jekyll build -d /data -s /usr/src/app/src > tmp/dist_container
docker start -a $$(cat tmp/dist_container)
@docker cp $$(cat tmp/dist_container):/data - | tar xf - -C dist --strip-components=1 > /dev/null
@docker stop $$(cat tmp/dist_container) > /dev/null
@docker rm -v $$(cat tmp/dist_container) > /dev/null
@rm -rf tmp/dist_container
$(PACKAGE): package.json
mkdir -p $(@D)
docker create -i --name installer -w /data $(NODE_VERSION) npm install
docker cp package.json installer:data/package.json
docker start -ai installer
docker cp installer:/data/node_modules - | gzip > $@
docker stop installer
docker rm installer
```
Here `docker cp` streams a tar file to stdout. That tar is extracted
to the proper directory. Also it uses a container ID (captured from
`docker create`) instead of a container name. You could give the
container a name if you prefer.
to the proper directory.
I hope this post clarifies how to implement the build container
pattern. It's astoundingly useful when done right. tl;dr: Use `docker
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment