Skip to content

Latest commit

 

History

History
191 lines (107 loc) · 6 KB

Docker-Runbook.md

File metadata and controls

191 lines (107 loc) · 6 KB

DOCKER RUNBOOK

DevOps Workshop Training

$\textcolor{brown}{\text{Contact us: }}$        

T O A C C E L E R A T E Y O U R C A R E E R G R O W T H

For questions and more details:

+91 98712 72900
+91 98712 72900


$\textcolor{red}{\text{NOTE: USE UBUNTU 22.04 VIRTUAL MACHINES FOR ALL THE LABS}}$

Find solutions to your assingment below:

Exercise 1: Accomplish below task to complete this exercise:**

a) Install docker on an Ubuntu GCP instance

Solution:

Refer Official Docker installation page for installation steps.

Post installation steps

i. Add your current user to docker group to allow access on docker commands:

sudo usermod -a -G docker $USER

ii. Logout from terminal and login to the user again

exit

b) Use docker pull to download docker images on this server

Solution:

docker pull nginx

image

c) Use docker run to run nginx container using this image. Use below parameters for the container

  • i. Name: mynginx

  • ii. Host port: 80

  • iii. Container port: 80

  • iv. Should run in detach mode

Solution:

docker run -ti -d --name mynginx -p 80:80 nginx

image

d) Login to mynginx container and check the nginx process running or not. Ideally it should be running:

Solution:

docker exec -ti mynginx bash

Install procps to run ps command inside container

image

e) Check if nginx is accessible on http://<Server_Pubilc_IP>:80 and you see below page:

image

Exercise 2: Accomplish below task to complete this exercise:**

a) Create a Dockerfile to package below:

  • i. uses ubuntu docker image

  • ii. Install apache2 inside it

  • iii. Mount any local html file from host to /var/www/html path of container

  • iv. Uses command as entrypoint: ENTRYPOINT apachectl -D FOREGROUND

Solution:

a) First, create a folder docker, in the home directory

mkdir docker
cd docker

image

Enter into this directory, and create a file called 'Dockerfile', with the same contents as the Sample Dockerfile. Add the following content in the Dockerfile.

sudo vim Dockerfile

Add the below content in Dockerfile

FROM ubuntu
ENV TZ=Asia/Kolkata
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ \> /etc/timezone
RUN apt-get update
RUN apt-get -y install apache2
ADD . /var/www/html
ENTRYPOINT apachectl -D FOREGROUND
ENV name Devops Tutorial

image

b) Create a sample html file with some content in the same directory as Dockerfile

Solution:

Create one more file called, index.html with the following contents can verify the push on DockerHub.

sudo vim index.html

Add the below content in html file

<html>
<title> Sample Website </title>
<body>
  Hello World
</body>
</html>

image

c) Once above Dockerfile is ready, perform below tasks:

  • i. Build the dockerfile with name ubuntu_apache

Solution:

docker build <directory-of-dockerfile> -t <name of image>

image

image

  • ii. Spawn a new container using below params:

    • Name: myapache

    • Host port: 81

    • Container port: 80

    • Should run in detach mode

Solution:

Run this built image, using the following command:

docker run –it –name myapache –p 81:80 –d <name of image>

image

  • iii. Check if apache is accessible on http://<Server_Pubilc_IP>:81 and you see the content of html file you created in step b.

Solution:

Navigate to the server IP address on port 81

_ Note: Make sure port 81 is open on the server using firewall rule_

image

Finally, login into the container, and check the variable $name, it will have the same value, as given in the Dockerfile.

image