Docker image for Docker Pipeline demo
This image contains a "Docker Pipeline" Job that demonstrates Jenkins Pipeline integration with Docker via Docker Pipeline plugin.
docker run --rm -p 127.0.0.1:8080:8080 -v /var/run/docker.sock:/var/run/docker.sock --group-add=$(stat -c %g /var/run/docker.sock) jenkinsci/docker-workflow-demo
docker run --rm -p 127.0.0.1:8080:8080 -v /var/run/docker.sock:/var/run/docker.sock --group-add=$(stat -f %g /var/run/docker.sock) jenkinsci/docker-workflow-demo
The "Docker Pipeline" Job simply does the following:
- Gets the Spring Pet Clinic demonstration application code from GitHub.
- Builds the Pet Clinic application in a Docker container.
- Builds a runnable Pet Clinic application Docker image.
- Runs a Pet Clinic app container (from the Pet Clinic application Docker image) + a second maven3 container that runs automated tests against the Pet Clinic app container.
- The 2 containers are linked, allowing the test container to fire requests at the Pet Clinic app container.
The "Docker Pipeline" Job demonstrates how to use the
docker.imageto define a DSL
Imageobject (not to be confused with
build) that can then be used to perform operations on a Docker image:
Image.insideto run a Docker container and execute commands in it. The build workspace is mounted as the working directory in the container.
Image.runto run a Docker container in detached mode, returning a DSL
Containerobject that can be later used to stop the container (via
docker.buildto build a Docker image from a
Dockerfile, returning a DSL
Imageobject that can then be used to perform operations on that image (as above).
docker DSL supports some additional capabilities not shown in the "Docker Pipeline" Job:
- Use the
docker.withServerto register endpoints for the Docker registry and host to be used when executing docker commands.
- Use the
Image.pullto pull Docker image layers into the Docker host cache.
- Use the
Image.pushto push a Docker image to the associated Docker Registry. See
The image needs to run Docker commands, so it assumes that your Docker daemon is listening to
/var/run/docker.sock (discussion). This is not “Docker-in-Docker”; the container only runs the CLI and connects back to the host to start sister containers. The
run target also makes reference to file paths on the Docker host, assuming they are where you are running that command, so this target cannot work on boot2docker. There may be some way to run this demo using boot2docker; if so, please contribute it.