Chapter 3. Developing with Docker

Prerequisites

  • Docker installed on your system.

    For more information on how to install Docker, see Get Docker.

  • You have obtained the Docker ID.

    For more information on how to get a Docker ID, see Register for a Docker ID.

3.1. Managing Docker connections

3.1.1. Setting up a Docker account in CodeReady Studio

The following section describes how to set up a Docker account in CodeReady Studio. The section assumes you completed the steps listed in the prerequisites section of this chapter.

Procedure

  1. Start CodeReady Studio.
  2. Click WindowPreferences.

    The Preferences window appears.

    crs registry accounts
  3. Enter Registry Accounts in the search field.
  4. Select Registry Accounts.
  5. Click Add.

    The New Registry Account window appears.

    crs docker new account registry
  6. Enter the Server Address for the Docker hub.
  7. Enter your Doker ID as the Username.
  8. Enter the email associated with your Docker account.
  9. Enter your password.
  10. Click OK.
  11. Click Apply and Close.

3.1.2. Testing the Docker connection

Prerequisites

Procedure

  1. Start CodeReady Studio.
  2. Click WindowShow ViewOther.

    The Show View window appears.

    crs opening docker explorer
  3. Enter Docker in the search field.
  4. Select Docker Explorer.
  5. Click Open.

    The Docker Explorer view appears.

    crs docker explorer
  6. Right-click Docker socketEdit.

    crs docker socket edit

    The Edit Docker Connection window appears.

    crs docker testing connection
  7. Click Test Connection.

    If the connection is configured correctly, a window stating that the Ping succeeded! appears.

  8. Click OK.
  9. Click Finish.

3.1.3. Editing the Docker connection

Prerequisites

Procedure

  1. Start CodeReady Studio.
  2. Click WindowShow ViewOther.

    The Show View window appears.

    crs opening docker explorer
  3. Enter Docker in the search field.
  4. Select Docker Explorer.
  5. Click Open.

    The Docker Explorer view appears.

    crs docker explorer
  6. Right-click Docker socketEdit.

    crs docker socket edit

    The Edit Docker Connection window appears.

    crs docker testing connection
  7. Click Browse in Unix socket Location field to locate a new socket or check the TCP Connection option and add the URI.
  8. Click Finish.

3.2. Managing Docker images

3.2.1. Pulling Docker images

Procedure

  1. Start CodeReady Studio.
  2. Click WindowShow ViewOther.

    The Show View window appears.

    crs opening docker explorer
  3. Enter Docker in the search field.
  4. Select Docker Explorer.
  5. Click Open.

    The Docker Explorer view appears.

    crs docker explorer
  6. Expand Docker socket folder.
  7. Right-click ImagesPull.

    crs docker pull images

    The Pull Image window appears.

    crs docker pull image window
  8. Click Search.

    The Search the Docker Registry for images window appears.

    crs docker pulling wildfly image
  9. Enter the image name in the search field.
  10. Click Next.

    The Choose a tag for the selected image window appears.

    crs docker images tags
  11. Choose a tag for your image.
  12. Click Finish.

    The Search the Docker Registry for images window appears.

    crs docker pulling wildfly image2
  13. Click Finish.

Your new Docker image is now listed in the Docker Explorer view.

crs docker pulled image

3.2.2. Pushing Docker images

Before pushing a Docker image you must tag it. The following section describes how to tag and push a Docker image in CodeReady Studio.

Procedure

  1. Start CodeReady Studio.
  2. Click WindowShow ViewOther.

    The Show View window appears.

    crs opening docker explorer
  3. Enter Docker in the search field.
  4. Select Docker Explorer.
  5. Click Open.

    The Docker Explorer view appears.

    crs docker explorer
  6. Expand Docker socketImages.
  7. Right-click the image you want to tag.
  8. Click Add tag.

    crs docker tag image

    The Tag Image window appears.

  9. Enter the tag in the New Tag field.

    The tag should be in the form of username/image_name:tag_name, where username is your Docker ID on https://hub.docker.com, image_name is the name of your image, and tag_name is the version of the image.

    crs docker tagging image
  10. Click Finish.
  11. Right-click the tagged imagePush.

    crs docker pushing tagged image

    The Push image to Registry window appears.

    crs docker image push
  12. Select the Registry Account that starts with your Docker ID.
  13. Click Finish.

After you push the image it appears in the Docker Cloud. This image is then available for other developers to use.

3.2.3. Running Docker images

Procedure

  1. Start CodeReady Studio.
  2. Click WindowShow ViewOther.

    The Show View window appears.

    crs opening docker explorer
  3. Enter Docker in the search field.
  4. Select Docker Explorer.
  5. Click Open.

    The Docker Explorer view appears.

    crs docker explorer
  6. Expand Docker socketImages.
  7. Right-click images you want to run.
  8. Click Run.

    crs docker running image

    The Docker Container settings window appears.

    crs docker container settings
  9. Name the container.
  10. Clear the Publish all exposed ports to random ports on the host interfaces check box.
  11. Check the box for 8080 port.
  12. Click Finish.

    The Console view appears showing the process of starting the image.

  13. In the web browser navigate to http://localhost:8080/ to see the image running.

    crs docker image running

3.2.4. Building images with Dockerfile

You can build an image or create one by modifying an existing image. Typically, this involves installing new packages. The specification of the new Docker image is done via a the Dockerfile

Prerequisites

Procedure

  1. Start CodeReady Studio.
  2. Click WindowShow ViewOther.

    The Show View window appears.

    crs opening docker images view
  3. Enter Docker in the search field.
  4. Select Docker Images.
  5. Click Open.

    The Docker Images view appears.

    crs docker images view
  6. Click the Build Image icon.

    crs docker build image icon

    The Build a Docker Image window appears.

    crs building a docker image
  7. Name the image in the format of repo/name:version.
  8. Click Browse to locate the Dockerfile.
  9. Click Finish.

The Console view appears displaying the build process.

3.3. Managing Docker Containers

Docker containers are isolated processes that are based on Docker images. Once created, users can stop, start, pause, unpause, kill, or remove the containers, as well as read their logs.

The following section describes how to manage Docker containers in CodeReady Studio.

Procedure

  1. Start CodeReady Studio.
  2. Click WindowShow ViewOther.

    The Show View window appears.

    crs opening docker containers view
  3. Enter Docker into the search field.
  4. Select Docker Containers.
  5. Click Open.

    The Docker Containers view appears.

    crs docker containers view

You can start, pause, unpause, stop, kill, restart, remove, or refresh the containers by using the panel.

crs docker containers control panel