US flag signifying that this is a United States Federal Government website An official website of the United States government

Deploying Docker images

Deploying Docker images

As an alternative to using buildpacks, you can push applications based on Docker.

To push a Docker image, use the --docker-image flag when pushing your app, for example:

cf push lattice-app --docker-image cloudfoundry/lattice-app

You can also push an image from a private Docker registry by providing the host and authentication information, as in this example:

CF_DOCKER_PASSWORD=YOUR-PASSWORD cf push APP-NAME --docker-image REPO/IMAGE:TAG --docker-username USER

Details are in the Cloud Foundry documentation for deploying an app with Docker. If you want to build your own Docker image, or if you want to read more about the implementation, check out the Docker documentation in the Cloud Foundry project.

Once you push a Docker image as your application, cloud.gov cannot update the baseline for your application, so you are responsible for keeping it up to date. You are responsible for maintaining the operating system, libraries, application code, and all of the associated configuration (losing some of the benefits of a PaaS environment). See this chart of responsibilities.

Here are some considerations to keep in mind when deciding to use Docker images instead of supported buildpacks in your application’s deployment:

Supported buildpack Docker container
Pros It “just works”.
Automatic and constant security updates.
All you need to do is write code.
Can build container images and run containers on local workstation.
Fine-grained control over compilation and root filesystem.
Cons Difficult to recreate the execution environment locally.
Testing compilation and the result of staging is harder.
Added responsibility for all security updates and bug fixes.
More compliance responsibility means more work.

Docker as tasks

There is a Cloud Foundry API for tasks creation. This allows single, one-off tasks to be triggered through the API.

Docker + Cloud Foundry examples

Spring Music

We often use the Spring Music app to demonstrate the use of database services on Cloud Foundry. The same application works when bundled into a Docker image, and works identically.

For example, push it to cloud.gov using a prebuilt Docker image with an in-memory database:

cf push my-spring --docker-image pburkholder/my-springmusic -m 1016M

Then create a database service, bind it, and restage the app to use the database:

cf create-service aws-rds shared-psql my-spring-db
cf bind-service my-spring my-spring-db
cf restage my-spring-db

Docker task with S3 and CF CLI Variable

The folks at Stark and Wayne have published a useful demo of packaging a shell script into a Docker image, then pushing it to Cloud Foundry with the necessary environment variables.