Switching a Liberty Docker server between run and debug mode using developer tools

For our Liberty Docker server, we can use WebSphere Developer Tools to switch the server between run and debug mode. When you switch between these modes, the tools create a Docker image and a Docker container, which we can save.

We must create a Liberty Docker server using WebSphere Developer Tools. For more information about using WebSphere Developers Tools to create a Liberty server in a Docker container, see Create a workbench Liberty server in a Docker container using developer tools.

When we create a Liberty server in a Docker container, the run command and host mapped ports are fixed. As a result, when you switch a Liberty Docker server between run and debug modes, WebSphere Developer Tools commit a new Docker image based on your Docker container. This action preserves all of the changes to the container at that point. Then, the tools create a new container from the new image, but modify the run command to either run or debug the server. When you switch to debug mode, the tools map the debug port to the host.

The tools do not delete the original image and container. However, the tools remove any temporary images and containers when you switch modes. To avoid losing changes that you made to the server in debug mode, we can save the last temporary image and container when you delete a Liberty Docker server.

  1. Switch the server from run mode to debug mode:

    1. Open the Servers view in WebSphere Developer Tools by clicking Window > Show view > Servers.
    2. Start the server in debug mode by right-clicking your_server and selecting Debug. The tools go through the following steps:

      1. Disconnect from the your_server container and stop the container.
      2. Commit the your_server container to a new image that is named your_server_debug_websphere-liberty

      3. Create a new container that is named your_server_debug from the your_server_debug_websphere-liberty image.
      4. Connect to the your_server_debug container.

    3. If the tools display the Server Execution Mode Switch window, click OK to continue.

      The tools display the Server Execution Mode Switch window only the first time that you switch the mode for the server.

  2. Switch the server back to run mode from debug mode by right-clicking your_server and selecting Run. The tools go through the following steps:

    1. Disconnect from the your_server_debug container and stop the container.
    2. Commit the your_server_debug container to a new image that is named your_server_run_websphere-liberty

    3. Create a new container that is named your_server_run from the your_server_run_websphere-liberty image.
    4. Connect to the your_server_run container.
  3. Delete the your_server server by right-clicking your_server and selecting Delete.

  4. Click Yes to save the your_server_run container and the your_server_run_websphere-liberty image.
You switched the server from run mode to debug mode and back to run mode. When you switched back to run mode, you saved any changes that you made to the container and image when you were in debug mode.