Unit-2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

UNIT-2

Testing web applications with Docker


To speed up the testing cycles, you need to start running the test scripts without worrying about
setting up the environment. A Docker container can wrap a complete runtime environment that
you need to quickly get started. You do not need to install the software on your physical
machine.
Before you begin
• Install Docker and start it. See the installation topic.
• If you are connecting to a remote Linux machine to run the image, to export the display
of the product and web browser, install a remote client and X server software.

About this task


You have a web application to test in different runtime environment such as platforms and
browsers. To test, you need to have either the physical machines or virtual machines for each of
the platforms. The more platforms that your web application supports, the more machines that
are required.

A Docker container can wrap a complete runtime environment that you need to quickly get
started. You do not need to install the software on your physical machine. For instance, to test
your web application on Ubuntu 16.04 with IBM® Rational® Functional Tester on the Google
Chrome browser, you do not need to install Ubuntu, Rational Functional Tester, or Chrome on
the physical machine. They can be wrapped in a Docker image and launched on various physical
machines.

Procedure
1. Download Dockerfile from Continuous Testing and also download Installation
Manager to the same folder.

Note:

Rational Functional Tester supports IBM Installation Manager v1.8.6 or later.

2. Log in to the Ubuntu machine as a root or sudo user and point to the folder where
Dockerfile is installed.
3. To see whether Docker is running as expected, run the following commands:

Docker commands
Command Description
docker
Checks the version of docker.
version
Runs the sample hello-world image. If the command returns hello
docker run hello-
world, you are all set to start using Rational Functional Tester on
world
Docker.

4. To build the image, run the following command:

docker build –build-arg IM_USERNAME= –build-arg IM_PASSWD= -t


imageName :imageVersion

Docker build commands

Command Description
Build Builds the image
–build-arg Defines a variable that you can pass to the build command at build time.

Note: You must specify the IBM ID user name and password in the command.

Tip:

o If you have changed the file name of the Dockerfile, you must add –
f DockerfileName to the build command.
o When an image is getting created and you run the command to view all of the
images, an entry called none is listed for the in-progress image.

When you create the image for the first time, this command takes several minutes
because it installs IBM Installation Manager, Rational Functional Tester and the web
browser (Firefox, Chrome, or both). The next time onwards Docker fetches the files
from the cache and builds the image faster.

5. To run the image, run the following command:

docker run -it –privileged -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-


unix -v hostPath/c:containerPath imageName:imageVersion
Command Description
-it Assigns a psuedo name to the container.
-privileged Required when running an image that includes Google Chrome.
-e Exports the display of UI.
-v Specifies the source path and target path to display the UI.
-v hostPath/c:containerPath Mounts the workspace on the host machine.
imageName:imageVersion Specifies the name of the image and its version to run.
Tip:

o The docker run command might fail if you did not run the command to export the
display of UI. The command to export the display of UI might differ based on the
remote client and X server that you use.
o To remove the image when you exit Docker, add –rm to the build command.

Rational Functional Tester is started. You can now record or run a test.

Continuous Integration using Docker


Certainly! Let's dive into more details about the CI/CD pipeline in Docker.

1. Continuous Integration (CI):

• Developers work on different features or bug fixes in parallel and commit their changes
to a shared version control system (e.g., Git).

• A CI server continuously monitors the repository for code changes.

• Whenever new code is committed, the CI server automatically triggers a build process.

• The CI server pulls the latest code from the repository and starts building a Docker
container.

• During the build process, the necessary dependencies, libraries, and configurations are
added to the container.

• Unit tests and other automated tests are executed within the container to verify that
the code functions correctly and meets quality standards.

• If any issues or failures occur during the build or testing phase, the CI server notifies the
development team, allowing them to fix the problems early on.

2. Continuous Delivery/Deployment (CD):

• Once the CI process is complete and all tests pass successfully, the container is
considered "ready" for deployment.

• The container image is tagged with a version number or other identifier to keep track of
different releases.

• The container image is pushed to a container registry, which serves as a centralized


repository for storing and distributing container images (e.g., Docker Hub, Amazon ECR).
• The CD process takes over and pulls the latest container image from the registry.

• Depending on predefined rules and configurations, the CD process deploys the


container to different environments, such as staging or production servers.

• Infrastructure configurations, such as networking, storage, and environment variables,


are applied to the deployed container to ensure it runs correctly in the target
environment.

• Once the container is deployed, the software becomes accessible to users or other
systems.

Benefits of CI/CD pipeline in Docker:

• Consistency and Portability: Docker containers encapsulate the application and its
dependencies, ensuring consistent behavior across different environments. This eliminates the
"it works on my machine" problem and makes deployments more reliable.

• Isolation and Scalability: Each container runs in isolation, preventing conflicts between different
applications and allowing horizontal scaling by running multiple containers concurrently.

• Faster Feedback and Faster Releases: CI/CD automation allows for rapid feedback on code
changes, enabling developers to detect and fix issues early. It also enables faster release cycles,
as the deployment process becomes automated and streamlined.

• Rollback and Versioning: Docker container images can be tagged with version numbers, making
it easier to track and roll back to previous releases if needed.

Overall, the CI/CD pipeline in Docker helps teams to automate the software development and
deployment processes, improving collaboration, code quality, and the speed at which applications are
delivered to end-users.

To manage a multi-configuration job in Docker


To manage a multi-configuration job in Docker, you can use Docker Compose, which is a tool for defining
and running multi-container Docker applications. Docker Compose allows you to manage multiple
containers and their configurations as a single unit. Here's how you can set up and manage a multi-
configuration job using Docker Compose:

1. Install Docker Compose:


- Visit the official Docker Compose documentation (https://docs.docker.com/compose/install/) and
follow the installation instructions for your specific operating system.

2. Define your Docker Compose file:

- Create a new file called `docker-compose.yml` in your project directory.

- In this file, you'll define the services (containers) and their configurations.

3. Configure services in the Docker Compose file:

- Define each service/container you want to run as a separate configuration block under the `services`
section.

- Specify the image or build context for each service. You can use a pre-built image from Docker Hub or
build your own Docker image.

- Configure the necessary environment variables, volumes, network settings, ports, and other
configuration options for each service.

4. Use environment variables for configuration:

- You can use environment variables within your Docker Compose file to manage different
configurations. Set the environment variables at runtime or use a `.env` file to store the configuration
values.

- Use these environment variables within the Docker Compose file to dynamically configure your
services.

5. Start and manage the multi-configuration job:

- Open a terminal or command prompt and navigate to the directory containing the `docker-
compose.yml` file.

- Run the command `docker-compose up` to start all the services defined in the Docker Compose file.

- Docker Compose will create and manage the necessary containers based on your configurations.

- You can use additional Docker Compose commands like `docker-compose down`, `docker-compose
stop`, and `docker-compose restart` to manage the running containers.
By following these steps, you can effectively manage a multi-configuration job using Docker Compose. It
allows you to define and control multiple containers and their configurations as a unified application,
simplifying the management and deployment process.

[ Building services with docker ]


Building application services with Docker

Building application services with Docker is a popular approach to containerization and deployment.
Docker allows you to package your application and its dependencies into a standardized container,
providing consistency and portability across different environments. Here's a step-by-step guide to
building application services with Docker:

1. Define your application: Start by understanding the components of your application and how they
interact. Identify the services, dependencies, and configurations required for your application to
run successfully.

2. Write a Dockerfile: The Dockerfile is a text file that contains instructions for building a Docker
image. It specifies the base image, sets up the environment, copies application code, installs
dependencies, and configures the container. You can use various Docker commands and
instructions to achieve this.

3. Create a Docker image: Use the Docker build command to create a Docker image based on the
instructions defined in the Dockerfile. This process involves building the image layer by layer,
caching intermediate layers to speed up subsequent builds.

arduinoCopy code

$ docker build -t your-image-name:tag .

4. Test the Docker image: Once the Docker image is built, you can create a Docker container from it
to test if your application runs as expected. Make sure to expose the required ports and volumes
for communication and data persistence.

arduinoCopy code

$ docker run -p host-port:container-port -v host-path:container-path your-image-name:tag

5. Push the Docker image: If you want to share your Docker image or deploy it to a remote server,
you need to push it to a container registry. Popular container registries include Docker Hub,
Amazon Elastic Container Registry (ECR), and Google Container Registry (GCR).
rubyCopy code

$ docker login registry-url $ docker push your-image-name:tag

6. Orchestrate with Docker Compose or Kubernetes: If your application requires multiple containers
or services, you can use Docker Compose or Kubernetes to orchestrate and manage them. Docker
Compose allows you to define a multi-container application using a YAML file, while Kubernetes is
a more robust container orchestration platform.

• Docker Compose: Create a docker-compose.yml file, specifying the services, networks,


volumes, and dependencies of your application. Then use the docker-compose up
command to start all the services.

• Kubernetes: Create Kubernetes manifests (YAML or JSON files) that describe your
application's containers, deployments, services, and other resources. Use the kubectl
command to apply these manifests to a Kubernetes cluster.

That's a high-level overview of building application services with Docker. It's important to note that
Docker is just one piece of the containerization ecosystem, and there are other tools and techniques
available depending on your specific needs.

You might also like