Container Service: Developing an Application - Docker Quick Reference Guide


This document provides tips for developing Docker applications on a local machine.

Vendor documentation: 
Docker Vendor Documentation
OpenShift Documentation: Working With Images

Efficient Dockerfiles

The Docker build process caches where possible to speed up builds. To optimize this process, order actions in the Dockerfile so that commands that usually produce the same result, or that are unlikely to change, are placed before commands which are volatile, like the inclusion of source code. For example, place the update of packages, setting of environmental variables or directory creation and permission updates in your Dockerfile before including source code that is under active development.

Build Fails On Status Code That Can Be Ignored

A RUN command in a Dockerfile may sometimes return non 0 exit status even though the issue isn't important. To ignore that ensure that the command returns 0. For example:

RUN find / -name -ls; exit 0;

Docker Runs Out of Space

When developing an application on your local computer, if Docker is giving out of space errors, use: 

docker system df

docker system info

to verify the problem and use:

docker system prune

to free up space.

Mounting Volumes Locally

While developing applications to run on OpenShift it may be useful to be able to run the application locally without OpenShift.  One issue is that OpenShift provides some environment conveniences that Docker does not.  In particular it will take care of mounting external storage, such as file systems and secrets, at designated locations in the container.  

This is an example of mounting the contents of temp/my-app/httpd-conf/  inside your running container at /tmp/apache-conf directly with Docker.

docker run -it -p 443:443 -v /temp/my-app/httpd-conf:/tmp/apache-conf my-app

This can be very useful for running an application container locally with Docker without needing to change the container for running on OpenShift.

Docker Compose

OpenShift can leverage docker compose applications. The kubernetes community maintains a tool called kompose that converts compose applications into Kubernetes/OpenShift format, and can alternatively bring the apps up or down.

  • More documentation on kompose is available here.
  • The matrix of support docker compose syntax is available here.
Last Updated: 
Thursday, July 9, 2020