Kode Kloud Docker

Date: 22 June 2023
Tasks: Install Docker Package 

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

Date: 21 July 2023
   
Tasks: Pull Docker Image


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.

Task: Create a Docker Network
The Nautilus DevOps team needs to set up several docker environments for different applications. One of the team members has been assigned a ticket where he has been asked to create some docker networks to be used later. Complete the task based on the following ticket description:
a. Create a docker network named as news on App Server 1(stapp01) in Stratos DC.
b. Configure it to use macvlan drivers.
c. Set it to use subnet 172.168.0.0/24 and iprange 172.168.0.0/24.

Solution: 

stapp01 172.16.238.10 stapp01.stratos.xfusioncorp.com tony Ir0nM@n Nautilus App 1
# ssh tony@stapp01
[root@stapp01 ~]# docker --version
[root@stapp01 ~]# systemctl status docker
[root@stapp01 ~]# docker network create --driver macvlan --subnet=172.168.0.0/24 --ip-range=172.168.0.0/24 news
[root@stapp01 ~]# docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
a35de4782bc8   bridge    bridge    local
e60452e8b7a4   host      host      local
49295530c13d   news      macvlan   local
804fbc91a240   none      null      local
[root@stapp01 ~]# 


Date: 30 Jan 2025
Task: Docker Volumes Mapping

The Nautilus DevOps team is testing applications containerization, which is supposed to be migrated on docker container-based environments soon. In today's stand-up meeting one of the team members has been assigned a task to create and test a docker container with certain requirements. Below are more details:
  1. On App Server 1 (stapp01) in Stratos DC pull nginx image (preferably latest tag but others should work too).
  2. Create a new container with name apps from the image you just pulled.
  3. Map the host volume /opt/finance with container volume /home. There is an sample.txt file present on same server under /tmp; copy that file to /opt/finance. Also please keep the container in running state.
Solution: 

[root@stapp01 ~]# docker pull nginx:latest
latest: Pulling from library/nginx
af302e5c37e9: Pull complete 
207b812743af: Pull complete 
841e383b441e: Pull complete 
0256c04a8d84: Pull complete 
38e992d287c5: Pull complete 
9e9aab598f58: Pull complete 
4de87b37f4ad: Pull complete 
Digest: sha256:0a399eb16751829e1af26fea27b20c3ec28d7ab1fb72182879dcae1cca21206a
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@stapp01 ~]# mkdir -p /opt/finance
[root@stapp01 ~]# cp /tmp/sample.txt /opt/finance/
[root@stapp01 ~]# docker run -d --name apps -v /opt/finance:/home nginx:latest
40d4797ec0f2039307619d7d6455bc00ed944d848e04586a23f40b362e0dd5f5
[root@stapp01 ~]# 
Date: 31 Jan 2025
Task: Docker Volumes Mapping

The Nautilus DevOps team is planning to host an application on a nginx-based container. There are number of tickets already been created for similar tasks. One of the tickets has been assigned to set up a nginx container on Application Server 1 in Stratos Datacenter. Please perform the task as per details mentioned below:
  • Pull nginx:alpine-perl docker image on Application Server 1.
  • Create a container named ecommerce using the image you pulled.
  • Map host port 8083 to container port 80. Please keep the container in running state.
Solution: 

[root@stapp01 ~]# docker pull nginx:alpine-perl
alpine-perl: Pulling from library/nginx
66a3d608f3fa: Pull complete 
58290db888fa: Pull complete 
5d777e0071f6: Pull complete 
dbcfe8732ee6: Pull complete 
37d775ecfbb9: Pull complete 
e0350d1fd4dd: Pull complete 
1f4aa363b71a: Pull complete 
e74fff0a393a: Pull complete 
db9f5fb52ce7: Pull complete 
Digest: sha256:8c6c1de96f71404c437e141cf0e04cf24ee176b8a965df6fce3691bdb542136e
Status: Downloaded newer image for nginx:alpine-perl
docker.io/library/nginx:alpine-perl
[root@stapp01 ~]# docker run -d --name ecommerce -p 8083:80 nginx:alpine-perl
c73f220523e2a9672d91fbce4a0da9fd7984f72433dbd0f4d3e3001f62bd31dd
[root@stapp01 ~]# docker images
REPOSITORY   TAG           IMAGE ID       CREATED        SIZE
nginx        alpine-perl   56e6f510baee   2 months ago   84.6MB
[root@stapp01 ~]# docker ps
CONTAINER ID   IMAGE               COMMAND                  CREATED          STATUS          PORTS                  NAMES
c73f220523e2   nginx:alpine-perl   "/docker-entrypoint.…"   18 seconds ago   Up 15 seconds   0.0.0.0:8083->80/tcp   ecommerce
[root@stapp01 ~]# 

Date: 31 Jan 2025
Task: Save, Load and Transfer Docker Image 

One of the DevOps team members was working on to create a new custom docker image on App Server 1 in Stratos DC. He is done with his changes and image is saved on same server with name games:datacenter. Recently a requirement has been raised by a team to use that image for testing, but the team wants to test the same on App Server 3. So we need to provide them that image on App Server 3 in Stratos DC.
  1. On App Server 1(stapp01) save the image games:datacenter in an archive.
  2. Transfer the image archive to App Server 3 (stapp03).
  3. Load that image archive on App Server 3 with same name and tag which was used on App Server 1.
Note: Docker is already installed on both servers; however, if its service is down please make sure to start it.

Solution: 
  • stapp01 172.16.238.10 stapp01.stratos.xfusioncorp.com tony Ir0nM@n Nautilus App 1
  • stapp03 172.16.238.12 stapp03.stratos.xfusioncorp.com banner BigGr33n Nautilus App 3
# ssh tony@stapp01
[root@stapp01 ~]# docker image ls
REPOSITORY   TAG          IMAGE ID       CREATED          SIZE
games        datacenter   5c9f375f5b01   12 minutes ago   123MB
ubuntu       latest       b1d9df8ab815   2 months ago     78.1MB
[root@stapp01 ~]# docker save -o /tmp/games_datacenter.tar games:datacenter
[root@stapp01 ~]# scp /tmp/games_datacenter.tar banner@stapp03:/tmp/
banner@stapp03's password: 
games_datacenter.tar                               100%  120MB  42.9MB/s   00:02    
[root@stapp01 ~]# ssh banner@stapp03
banner@stapp03's password: 
[banner@stapp03 ~]$ sudo su -
[root@stapp03 ~]# docker image ls
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
[root@stapp03 ~]# docker load -i /tmp/games_datacenter.tar
687d50f2f6a6: Loading layer  80.63MB/80.63MB
f7d66fb7a9aa: Loading layer  45.15MB/45.15MB
Loaded image: games:datacenter
[root@stapp03 ~]# docker image ls
REPOSITORY   TAG          IMAGE ID       CREATED          SIZE
games        datacenter   5c9f375f5b01   16 minutes ago   123MB
[root@stapp03 ~]# 

Date: 06 Feb 2025
Task: Write a Docker Compose File 
The Nautilus application development team shared static website content that needs to be hosted on the httpd web server using a containerised platform. The team has shared details with the DevOps team, and we need to set up an environment according to those guidelines. Below are the details:
  1. On App Server 3(stapp03) in Stratos DC create a container named httpd using a docker compose file /opt/docker/docker-compose.yml (please use the exact name for file).
  2. Use httpd (preferably latest tag) image for container and make sure container is named as httpd; you can use any name for service.
  3. Map 80 number port of container with port 6000 of docker host.
  4. Map container's /usr/local/apache2/htdocs volume with /opt/finance volume of docker host which is already there. (please do not modify any data within these locations).
Solution:

stapp03 172.16.238.12 stapp03.stratos.xfusioncorp.com banner BigGr33n Nautilus App 3

# ssh banner@stapp03
[root@stapp03 ~]# cat /opt/finance/index1.html 
Welcome to xFusionCorp Industries.
[root@stapp03 ~]# vi /opt/docker/docker-compose.yml
version: '3'
services:
  web:
    image: httpd:latest
    container_name: httpd
    ports:
      - "6000:80"
    volumes:
      - /opt/finance:/usr/local/apache2/htdocs

[root@stapp03 docker]# curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 61.6M  100 61.6M    0     0  84.4M      0 --:--:-- --:--:-- --:--:--  137M
[root@stapp03 docker]# chmod +x /usr/local/bin/docker-compose
[root@stapp03 docker]# docker-compose --version
Docker Compose version v2.32.4
[root@stapp03 docker]# docker-compose up -d
WARN[0000] /opt/docker/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Running 7/7
 ✔ web Pulled                                                                   8.4s 
   ✔ c29f5b76f736 Pull complete                                                 3.6s 
   ✔ 830a84f99cc8 Pull complete                                                 4.0s 
   ✔ 4f4fb700ef54 Pull complete                                                 4.4s 
   ✔ a1a1b409f475 Pull complete                                                 5.2s 
   ✔ 35b1ecb71608 Pull complete                                                 7.4s 
   ✔ 80350326cd93 Pull complete                                                 8.1s 
[+] Running 2/2
 ✔ Network docker_default  Created                                              0.2s 
 ✔ Container httpd         Started                                              2.6s 
[root@stapp03 docker]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
httpd        latest    4d98e80840bb   13 days ago   148MB
[root@stapp03 docker]# docker ps -a
CONTAINER ID   IMAGE          COMMAND              CREATED              STATUS              PORTS                  NAMES
6a3b079ee2da   httpd:latest   "httpd-foreground"   About a minute ago   Up About a minute   0.0.0.0:6000->80/tcp   httpd
[root@stapp03 docker]# 

No comments:

Post a Comment