Kode Kloud Docker

Tasks: Install Docker Package 
Date:  6/22/2023

Last week the Nautilus DevOps team met with the application development team and decided to containerize several of their applications. The DevOps team wants to do some testing per the following:
1. Install docker-ce and docker-compose packages on App Server 2
2. Start docker service.
Solution: 
To install Docker CE and Docker Compose on App Server 2 and start the Docker service, follow these steps:

Step 1: Install Docker CE
1. Update the package index:

# yum update -y
  
2. Install required packages:

# yum install -y yum-utils
   
3. Add Docker's official GPG key:

# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
   
4. Install Docker CE:

# yum install -y docker-ce docker-ce-cli containerd.io
   
Step 2: Start Docker Service

1. Enable and start Docker:

# systemctl enable docker
# systemctl start docker

2. Verify Docker installation:

# docker --version
# docker run hello-world
   
Step 3: Install Docker Compose

1. Download the Docker Compose binary:

# curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
   
2. Apply executable permissions to the Docker Compose binary:

# chmod +x /usr/local/bin/docker-compose
 
3. Verify Docker Compose installation:

# docker-compose --version
   
Tasks: Pull Docker Image
Date: 7/21/2023

Nautilus project developers are planning to start testing on a new project. As per their meeting with the DevOps team, they want to test containerized environment application features. As per details shared with DevOps team, we need to accomplish the following task:
a. Pull busybox:musl image on App Server 3 in Stratos DC and re-tag (create new tag) this image as busybox:media

Solution: 

To pull the `busybox:musl` image and re-tag it as `busybox:media` on App Server 3 in Stratos DC, follow these steps:

1. Log in to App Server 3:

Connect to App Server 3 via SSH.

2. Pull the `busybox:musl` image:

# docker pull busybox:musl  

3. Re-tag the image:

# docker tag busybox:musl busybox:media
   
4. Verify the images:
   
# docker images

Run the commands step-by-step and ensure that each command executes successfully.


Task: Deploy an App on Docker Containers

The Nautilus Application development team recently finished development of one of the apps that they want to deploy on a containerized platform. The Nautilus Application development and DevOps teams met to discuss some of the basic pre-requisites and requirements to complete the deployment. The team wants to test the deployment on one of the app servers before going live and set up a complete containerized stack using a docker compose fie. 
Below are the details of the task:
1. On App Server 2 in Stratos Datacenter create a docker compose file /opt/data/docker-compose.yml (should be named exactly).
2. The compose should deploy two services (web and DB), and each service should deploy a container as per details below:
For web service:
a. Container name must be php_blog.
b. Use image php with any apache tag. Check https://hub.docker.com/_/php?tab=tags/ style=color:#0000FF; target=_blank>here for more details.
c. Map php_blog container's port 80 with host port 5003
d. Map php_blog container's /var/www/html volume with host volume /var/www/html.

For DB service:
a. Container name must be mysql_blog.
b. Use image mariadb with any tag (preferably latest). Check https://hub.docker.com/_/mariadb?tab=tags/ style=color:#0000FF; target=_blank>here for more details.
c. Map mysql_blog container's port 3306 with host port 3306
d. Map mysql_blog container's /var/lib/mysql volume with host volume /var/lib/mysql.
e. Set MYSQL_DATABASE=database_blog and use any custom user ( except root ) with some complex password for DB connections.

3. After running docker-compose up you can access the app with curl command curl <server-ip or hostname>:5003/
For more details check https://hub.docker.com/_/mariadb?tab=description/ style=color:#0000FF; target=_blank>here.

Solution: 

To complete the task of setting up a Docker Compose file on App Server 2 in the Stratos Datacenter, follow these steps:

Step 1: Create the Docker Compose File

# vi /opt/data/docker-compose.yml
version: '3'
services:
  web:
    container_name: php_blog
    image: php:7.4-apache
    ports:
      - "5003:80"
    volumes:
      - /var/www/html:/var/www/html

  db:
    container_name: mysql_blog
    image: mariadb:latest
    ports:
      - "3306:3306"
    volumes:
      - /var/lib/mysql:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: root_password
      MYSQL_DATABASE: database_blog
      MYSQL_USER: custom_user
      MYSQL_PASSWORD: complex_password

Step 2: Save the Docker Compose File

Save the above content to the file `/opt/data/docker-compose.yml`:

# mkdir -p /opt/data
# vi /opt/data/docker-compose.yml

Paste the content into the file and save it.

Step 3: Create Required Directories

Ensure the directories for volume mappings exist:

# mkdir -p /var/www/html
# mkdir -p /var/lib/mysql

Step 4: Run Docker Compose

Navigate to the directory containing the Docker Compose file and start the services:

# cd /opt/data
# docker-compose up -d

Step 5: Verify the Deployment

Check if the containers are running:

# docker ps

You should see `php_blog` and `mysql_blog` containers running.

Step 6: Test the Web Service

Test the web service using the `curl` command:

curl <server-ip>:5003/

Replace `<server-ip>` with the actual IP address of App Server 2.

Summary

1. Created a Docker Compose file at `/opt/data/docker-compose.yml`.
2. Defined services for web and database using `php:7.4-apache` and `mariadb:latest` images respectively.
3. Mapped appropriate ports and volumes.
4. Started the services using `docker-compose up -d`.
5. Verified the containers are running and tested the web service with `curl`.

By following these steps, you should have a functional Docker Compose setup with the specified web and database services.

No comments:

Post a Comment