Getting Started With Container and Cloud Based Development
Getting Started With Container and Cloud Based Development
17
Levi Valeeva
[email protected]
Supriya Takkhi
[email protected]
Yana Hontyk
[email protected]
Legal Notice
Copyright © 2020 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons
Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is
available at
http://creativecommons.org/licenses/by-sa/3.0/
. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must
provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert,
Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift,
Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States
and other countries.
Linux ® is the registered trademark of Linus Torvalds in the United States and other countries.
XFS ® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States
and/or other countries.
MySQL ® is a registered trademark of MySQL AB in the United States, the European Union and
other countries.
Node.js ® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the
official Joyent Node.js open source or commercial project.
The OpenStack ® Word Mark and OpenStack logo are either registered trademarks/service marks
or trademarks/service marks of the OpenStack Foundation, in the United States and other
countries and are used with the OpenStack Foundation's permission. We are not affiliated with,
endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
Abstract
This compilation of topics contains information on how to start developing containerized
applications and applications for cloud deployment.
Table of Contents
Table of Contents
.CHAPTER
. . . . . . . . . . 1.. .DEVELOPING
. . . . . . . . . . . . . . .USING
. . . . . . .CONTAINERS
. . . . . . . . . . . . . . .AND
. . . . .THE
. . . . .CLOUD
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3. . . . . . . . . . . . .
1.1. USING RED HAT CODEREADY CONTAINERS TOOLING IN CODEREADY STUDIO 3
1.1.1. Downloading and installing Red Hat CodeReady Containers in CodeReady Studio 3
1.1.2. Using the OpenShift Container Platform tooling 6
1.2. USING RED HAT CONTAINER DEVELOPMENT KIT TOOLING IN CODEREADY STUDIO 12
1.2.1. Installing Container Development Kit in CodeReady Studio 12
1.2.2. Using Docker tooling 17
1.2.2.1. Creating a Dockerfile 17
1.2.2.2. Building the Docker image Using the Container Development Environment 23
1.2.2.3. Additional resources 25
1.2.3. Using the OpenShift Container Platform tooling 25
1.2.4. Additional resources 31
.CHAPTER
. . . . . . . . . . 2.
. . DEVELOPING
. . . . . . . . . . . . . . . FOR
. . . . . THE
. . . . .CLOUD
. . . . . . . . WITH
. . . . . . OPENSHIFT
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
..............
2.1. CREATING AN OPENSHIFT CONTAINER PLATFORM APPLICATION IN CODEREADY STUDIO 32
2.1.1. Creating a new OpenShift Container Platform connection 32
2.1.2. Creating a new OpenShift Container Platform project 35
2.1.3. Creating a new OpenShift Container Platform application 37
2.1.4. Importing an existing OpenShift Container Platform application into the IDE 42
2.1.5. Deploying an application using the server adapter 45
2.1.6. Deleting an OpenShift Container Platform project 48
2.2. SETTING UP AND REMOTELY MONITORING AN OPENSHIFT CONTAINER PLATFORM APPLICATION
50
2.2.1. Setting up OpenShift Client Binaries 50
2.2.2. Setting up Port Forwarding 51
2.2.3. Streaming Pod Logs 54
2.2.4. Streaming Build Logs 56
2.3. ADDITIONAL RESOURCES 58
. . . . . . . . . . . 3.
CHAPTER . . DEVELOPING
. . . . . . . . . . . . . . . WITH
. . . . . . DOCKER
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .59
..............
3.1. MANAGING DOCKER CONNECTIONS 59
3.1.1. Setting up the Docker account in CodeReady Studio 59
3.1.2. Testing the Docker connection 60
3.1.3. Editing the Docker connection 63
3.2. MANAGING DOCKER IMAGES 65
3.2.1. Pulling Docker images 65
3.2.2. Pushing Docker images 70
3.2.3. Running Docker images 74
3.2.4. Building images with Dockerfile 78
3.3. MANAGING DOCKER CONTAINERS 80
1
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
2
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD
Prerequisites
1. Download the latest release of CodeReady Containers and the pull secret .
Procedure
3
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
4. Select Servers.
5. Click Open.
The Servers view appears.
4
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD
5
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
9. Click Next.
The CodeReady Containers window appears.
Your newly added CodeReady Containers 1.0+ server adapter is now listed in the Servers view.
Prerequisites
Procedure
6
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD
7
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
6. Click Open.
The OpenShift Explorer view appears.
7. Press Ctrl+N.
The Select a wizard window appears.
8
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD
9
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
10
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD
Your newly created OpenShift application project is now listed in the OpenShift Explorer view.
11
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
Additional resources
For more information on how to perform additional tasks with the OpenShift Container
Platform projects and application, see Developing for the Cloud with OpenShift.
Prerequisites
xhyve (macOS)
Hyper-V (Windows)
For more information on CDK, see the Red Hat Container Development Kit Getting Started Guide .
Procedure
12
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD
4. Select Servers.
5. Click Open.
The Servers view appears.
13
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
14
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD
9. Click Next.
The Red Hat Container Development Environment window appears.
15
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
13. Ensure that your sign-on credentials for access.redhat.com are correct.
15. Review and accept the license agreement and click Next.
16
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD
NOTE
In case you did not set up CDK prior to starting the server adapter, you will see a
warning: CDK has not been properly initialized!.
Prerequisites
For more information, see Section 1.2.1, “Installing Container Development Kit in
CodeReady Studio”.
Procedure
3. Press Ctrl+N.
The Select a wizard window appears.
18
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD
6. Click Next.
The New Java Project window appears.
19
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
9. Click Finish.
Your newly created Java project is now listed in the CodeReady Studio view.
20
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD
21
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
14. Paste the following content into your newly created file:
USER root
22
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD
# Add the WildFly distribution to /opt, and make wildfly the owner of the extracted tar content
# Make sure the distribution is available from a well-known place
RUN cd $HOME \
&& curl -O https://download.jboss.org/wildfly/$WILDFLY_VERSION/wildfly-
$WILDFLY_VERSION.tar.gz \
&& sha1sum wildfly-$WILDFLY_VERSION.tar.gz | grep $WILDFLY_SHA1 \
&& tar xf wildfly-$WILDFLY_VERSION.tar.gz \
&& mv $HOME/wildfly-$WILDFLY_VERSION $JBOSS_HOME \
&& rm wildfly-$WILDFLY_VERSION.tar.gz \
&& chown -R jboss:0 ${JBOSS_HOME} \
&& chmod -R g+rw ${JBOSS_HOME}
# Ensure signals are forwarded to the JVM process correctly for graceful shutdown
ENV LAUNCH_JBOSS_IN_BACKGROUND true
USER jboss
Additional resources
1.2.2.2. Building the Docker image Using the Container Development Environment
Prerequisites
Procedure
23
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
24
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD
7. Click OK.
The Console view appears displaying the docker image building process.
For more information about the basics of Docker Tooling, see Using Docker Tooling in
CodeReady Studio.
Prerequisites
Procedure
25
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
26
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD
6. Click Open.
The OpenShift Explorer view appears.
7. Press Ctrl+N.
The Select a wizard window appears.
27
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
28
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD
29
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
Your newly created OpenShift application project is now listed in the OpenShift Explorer view.
30
CHAPTER 1. DEVELOPING USING CONTAINERS AND THE CLOUD
Additional resources
For more information on how to perform additional tasks with the OpenShift Container
Platform projects and application, see Developing for the Cloud with OpenShift.
For more information on how to use OpenShift in CodeReady Studio, see OpenShift basics in
CodeReady Studio
31
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
Procedure
32
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT
5. Click Open.
The OpenShift Explorer view appears.
33
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
8. Paste the URL for the OpenShift server into the Server field.
NOTE
34
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT
NOTE
Alternatively, you can copy the Login Command from the OpenShift Container
Platform web UI.
To get login credentials, click the drop-down menu in the top right corner →
Copy Login Command
Your newly added connection is now listed in the OpenShift Explorer view.
Prerequisites
Procedure
35
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
5. Click Open.
The OpenShift Explorer view appears.
36
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT
8. Click Finish.
Your newly created OpenShift project is now listed in the OpenShift Explorer view.
Prerequisites
Procedure
37
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
5. Click Open.
The OpenShift Explorer view appears.
38
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT
8. Click Next.
The Template Parameters window appears.
9. Click Next.
The Resource Labels window appears.
39
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
40
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT
41
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
Your newly created OpenShift Container Platform application is now listed in the OpenShift Explorer
view.
Additional Resources
For more information about using and creating templates with OpenShift Container Platform,
see Using templates.
2.1.4. Importing an existing OpenShift Container Platform application into the IDE
The OpenShift Explorer view in the IDE lists applications associated with your OpenShift Container
Platform accounts. You can import the source code for these applications individually into the IDE using
the Import OpenShift Application wizard. After the application is imported, you can easily modify the
application source code, build the application, and view it in a web browser.
Prerequisites
The application that you are importing in the IDE has its source specified in the build config file.
Procedure
42
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT
5. Click Open.
The OpenShift Explorer view appears.
43
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
44
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT
8. Click Next.
The Import OpenShift application window appears.
Your newly imported OpenShift Container Platform application is now listed in the OpenShift Explorer
view.
Prerequisites
Procedure
45
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
5. Click Open.
The OpenShift Explorer view appears.
46
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT
8. Click Finish.
47
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
The CodeReady Studio built-in web browser opens, displaying your application.
Procedure
48
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT
5. Click Open.
The OpenShift Explorer view appears.
49
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
8. Click OK.
Prerequisites
Before setting up port forwarding or streaming application and build logs, it is mandatory to set up
OpenShift Client Binaries.
Procedure
50
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT
4. Select OpenShift.
Port forwarding must be enabled each time to connect to OpenShift Container Platform from the IDE.
Procedure
51
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
5. Click Open.
The OpenShift Explorer view appears.
52
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT
53
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
Procedure
54
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT
5. Click Open.
The OpenShift Explorer view appears.
55
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
Procedure
56
CHAPTER 2. DEVELOPING FOR THE CLOUD WITH OPENSHIFT
5. Click Open.
The OpenShift Explorer view appears.
57
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
58
CHAPTER 3. DEVELOPING WITH DOCKER
Prerequisites
Procedure
59
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
5. Click Add.
The New Registry Account window appears.
Prerequisites
Procedure
60
CHAPTER 3. DEVELOPING WITH DOCKER
5. Click Open.
The Docker Explorer view appears.
61
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
8. Click OK.
62
CHAPTER 3. DEVELOPING WITH DOCKER
9. Click Finish.
Prerequisites
Procedure
63
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
5. Click Open.
The Docker Explorer view appears.
64
CHAPTER 3. DEVELOPING WITH DOCKER
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.
Procedure
65
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
5. Click Open.
The Docker Explorer view appears.
66
CHAPTER 3. DEVELOPING WITH DOCKER
8. Click Search.
The Search the Docker Registry for imageswindow appears.
67
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
68
CHAPTER 3. DEVELOPING WITH DOCKER
69
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
You new Docker image is now listed in the Docker Explorer view.
Procedure
70
CHAPTER 3. DEVELOPING WITH DOCKER
5. Click Open.
The Docker Explorer view appears.
71
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
72
CHAPTER 3. DEVELOPING WITH DOCKER
73
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
12. Select the Registry Account that starts with your Docker ID.
After you push the image it appears in the Docker Cloud. This image is then available for other
developers to use.
Procedure
74
CHAPTER 3. DEVELOPING WITH DOCKER
5. Click Open.
The Docker Explorer view appears.
75
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
8. Click Run.
76
CHAPTER 3. DEVELOPING WITH DOCKER
10. Clear the Publish all exposed ports to random ports on the host interfacescheck box.
77
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
13. In the web browser navigate to http://localhost:8080/ to see the image running.
Prerequisites
Procedure
78
CHAPTER 3. DEVELOPING WITH DOCKER
5. Click Open.
The Docker Images view appears.
79
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
9. Click Finish.
The following section describes how to manage Docker containers in CodeReady Studio.
Procedure
80
CHAPTER 3. DEVELOPING WITH DOCKER
5. Click Open.
The Docker Containers view appears.
81
Red Hat CodeReady Studio 12.17 Getting Started with Container and Cloud-based Development
You can start, pause, unpause, stop, kill, restart, remove, or refresh the containers by using the panel.
82