Pivotal tc Server with Docker

Important Disclaimer: Pivotal is currently developing an overall plan for distributing Docker images and Dockerfiles. This is a generic guide to getting started with using tc Server with Docker. At this time official support for tc Server with Docker isn’t available. This document is intended to provide guidance until other options are available.

Security Considerations

When creating a docker image please consider the following:

  • The base image will be periodically updated with security updates. You will need to update your docker image with these updates. A CI/CD system is recommended for this.
  • tc Server releases updates periodically. You will need to develop a plan for keeping your images updated.

Base images

We recommend starting with the official Ubuntu Bionic (18.04) docker image and adding an official OpenJDK 8 or 11 binary on top of this image. An example is provided below.

Persisting Data

We recommend using volumes to persist data. The docker container itself should be treated as ephemeral.

By default tc Server uses a separated layout for the tc Runtime this makes it easy to mount a volume containing only the instance data.

Please see the documentation on Docker Volumes

Creating Docker Image Using Tooling

In order to stay up to date Pivotal recommends using a continuous integration tool such as concourse to generate new docker images when the base image or tc Server is updated. Please see the future section regarding setting that up.

This example assumes the docker image will be created using the ubuntu:bionic docker image as the base image. It also uses an OpenJDK version distributed by Pivotal.

This examples requires the following:

Manually Building a Docker Image

If you haven’t already done so you need to login to Pivotal Network and access your refresh token this is available via the Edit Profile page.

1.) Login to pivnet with the pivnet command

pivnet login --api-token REPLACE-WITH-YOUR-TOKEN

2.) Download the .debs

pivnet download-product-files --product-slug tc-server-4x-core --release-version 4.0.9 --glob "*.deb"
pivnet download-product-files --product-slug tc-server-4x-runtimes --release-version 9.0.27 --glob "*.deb"

3.) Download the JDK

pivnet download-product-files --product-slug pivotal-openjdk --release-version 1.8.0_222 --glob "openjdk-jdk-*-bionic.tar.gz"

4.) Create a Dockerfile

This is an example of a Dockerfile to use for creating a tc Server image. This image does not contain any tc Runtime Instances. More information on that in a later section.

Save the following as Dockerfile

FROM 'ubuntu:18.04'

COPY pivotal-tc-server_4.0.9-RELEASE_all.deb /tmp
COPY openjdk-jdk-1.8.0_222-bionic.tar.gz /tmp
COPY pivotal-tc-runtime-9_9.0.27.A-RELEASE_all.deb /tmp

RUN dpkg -i /tmp/pivotal-tc-server_4.0.9-RELEASE_all.deb /tmp/pivotal-tc-runtime-9_9.0.27.A-RELEASE_all.deb
RUN mkdir -p /opt/java/openjdk-jdk-1.8.0_222 && \
    tar xzf /tmp/openjdk-jdk-1.8.0_222-bionic.tar.gz -C /opt/java/openjdk-jdk-1.8.0_222

ENV TCSERVER_HOME=/opt/pivotal/tcserver/standard
ENV TCSERVER_RUNTIMES_DIRECTORY=/opt/pivotal/tcserver/runtimes
ENV TCSERVER_INSTANCES_DIRECTORY=/var/opt/pivotal/tcserver/instances

ENV JAVA8_HOME=/opt/java/openjdk-jdk-1.8.0_222
ENV JAVA_HOME=$JAVA8_HOME
ENV PATH=$TCSERVER_HOME:$JAVA_HOME/bin:$PATH
ENV INSTANCE_NAME=instance

USER tcserver
CMD $TCSERVER_HOME/tcserver run $INSTANCE_NAME

The above example sets up some environment variables which uses will be clearer in later sections. If your instance name will not be instance you may change the value of theINSTANCE_NAME ENV variable above or the variable may be overwritten when running docker.

5.) Build the image

docker image build . -t tc-server-standard:4.0.9

Using the Docker Image

This section covers how to use a docker image created in the previous section. If you have created your own not using the above examples, this section assumes that your docker image has

1.) the tcserver command on the path

2.) the CMD executes the following line tcserver run instance

If that is not the case you will need to make adjustments to the following example.

Option 1: Creating a tc Runtime Instance in a volume and running the container.

This example will create an instance and run the container.

1.) Create the instance, where instances is on the local system and it will contain the instance. This example names the instance as instance which is what the default instance name is based on the previous Dockerfile examples.

docker run -it -v instances:/var/opt/pivotal/tcserver/instances -p 8080:8080 tc-server-standard:4.0.9 tcserver create instance

2.) Run the container.

docker run -v instances:/var/opt/pivotal/tcserver/instances -p 8080:8080 tc-server-standard:4.0.9

You should now be able to access the tc Runtime Instance

curl http://localhost:8080/

You can copy your webapp to the instance’s webapp directory inside the volume.

Alternatively in your Dockerfile include a step to create the instance and copy the webapp. If you choose to create the instance in the Dockerfile then you do not need to create a volume and can run the container without a volume.

docker run -p 8080:8080 tc-server-standard:4.0.9