Skip to content

MuhammadHassanBashir/Docker-ITI

 
 

Repository files navigation

Docker ITI

Lab1

Problem1

plot

$ sudo docker run hello-world
$ sudo docker ps -a
$ sudo docker start 64d459f955b3
$ sudo docker rm 64d459f955b3
$ sudo docker images
$ sduo docker rmi feb5d9fea6a5

Problem2

plot

$ sudo docker run -it ubuntu
$ echo docker
$ touch hello-docker
$ sudo docker stop d3917c73d21d
$ sudo docker rm d3917c73d21d

# all files deleted once I removed the container

$ sudo docker container prune

Problem3

plot

$ sudo docker volume create vol
$ sudo docker run -it -v vol:/usr/share/nginx/html -p 8085:80 --name nginxCon5 nginx bash
$ cd /usr/share/nginx/html/
$ echo "Remon Louis" >> index.html 
$ service start nginx
$ sudo docker stop faa
$ sudo docker rm faa
$ sudo docker run -it -v vol:/usr/share/nginx/html -p 8088:80 --name nginxCon6 nginx bash
$ service start nginx

Problem4

plot

$ sudo docker run -it -p 8090:80 --name nginxCon8 nginx bash
$ cd /usr/share/nginx/html/
$ toch RemonLouis.html
$ echo "Remon Louis" >> RemonLouis.html 
$ sudo docker images
$ sudo docker commit ed579e1e3144 testimage:version1.0
FROM nginx
CMD [ "Remon Louis" ]
# Docker file created
$ sudo docker build -t remonlouis_image .

Problem5

plot

$ sudo docker run --name app-database9 -v mysql_data:/var/lib/mysql -p 3040:3306 -e MYSQL_ROOT_PASSWORD=P4sSw0rd0! -d mysql


Lab2

plot

P1

#created html page and change add dummy paragraph with name index.html
#Make tar file of index.html
$ tar -cvf index.tar index.html
FROM ubuntu:23.04

RUN apt-get update
RUN apt-get install nginx -y

COPY index.html /var/www/html
ADD index.tar /var/www/html

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
$ sudo docker build -t mynginx:v1.0 .
$ sudo docker run -d -p 9091:80 mynginx:v1.0

P2

  1. part1-SingleStage

# install node local on my machine and then create the react app

$ sudo apt install nodejs
$ sudo apt install npm
$ sudo npm i -g npx
$ sudo npx create-react-app my-app

# ---- I ignored react project node-modules file # create Dockerfile

# use a light image of node
FROM node:alpine3.16

# make directory (app) and cd the dir
WORKDIR /app

# copy src files to the Dist
COPY my-app/package*.json ./

# install packages
RUN npm install

# copy source code to the dist
COPY my-app/ .

# Port 3000
EXPOSE 3000

# start app
CMD [ "npm" , "start" ]

# bulid the image from this Dockerfile

$ sudo docker build -t remon-app:v1.0 .

# run a container from this generated image

$ sudo docker run -it --name remon-app -p 3009:3000 remon-app:v1.0

# check localhost:3009 and it is up and running

  1. part2-MultiStage
# use a light image of node
FROM node:alpine3.16 AS builderstage

# make directory (app) and cd the dir
WORKDIR /app

# copy src files to the Dist
COPY my-app/package*.json ./

# install packages
RUN npm install

# copy source code to the dist
COPY my-app/ .

# Port 3000
EXPOSE 3000

# start app
RUN npm run build


# use the nginx Base Image
FROM nginx:alpine

# copy the bulid result from the builderstage
COPY --from=builderstage /app/build /usr/share/nginx/html


# prot 80 for nginx
EXPOSE 80

# run nginx
CMD [ "nginx" , "-g" , "daemon off;" ]
$ sudo docker build -t my-app:v2.0 .
$ sudo docker run -it --name remon-multistage-app -p 6070:80 my-app:v2.0

# check localhost:6070 and it is up and running

P3

  1. bridge : The default network driver. If you don’t specify a driver, this is the type of network you are creating.
  2. host : For standalone containers, remove network isolation between the container and the Docker host, and use the host’s networking directly
  3. overlay : Overlay networks connect multiple Docker daemons together and enable swarm services to communicate with each other. You can also use overlay networks to facilitate communication between a swarm service and a standalone container, or between two standalone containers on different Docker daemons.
  4. ipvlan : IPvlan networks give users total control over both IPv4 and IPv6 addressing. The VLAN driver builds on top of that in giving operators complete control of layer 2 VLAN tagging and even IPvlan L3 routing for users interested in underlay network integration.
  5. macvlan: Macvlan networks allow you to assign a MAC address to a container, making it appear as a physical device on your network. The Docker daemon routes traffic to containers by their MAC addresses. Using the macvlan driver is sometimes the best choice when dealing with legacy applications that expect to be directly connected to the physical network, rather than routed through the Docker host’s network stack.
  6. none: or this container, disable all networking. Usually used in conjunction with a custom network driver. none is not available for swarm services.
  7. Network blugins : You can install and use third-party network plugins with Docker. These plugins are available from Docker Hub or from third-party vendors.

p4

# create a bridge network
$ sudo docker network create my-net

# create 2 containers and attatch them to bridge network I created
$ sudo docker run -d --name con1 --network my-net nginx
$ sudo docker run -d --name con2 --network my-net nginx

# inspect the network to make sure that the 2 containers are already attached to it

$ sudo docker network inspect my-net

# open first container to install ping package
$ sudo docker container exec -it con1 bash
$ apt-get update
$ apt-get install inetutils-ping

# back to my local machine and try to ping second container from the first one
$ sudo docker exec -ti con1 ping con2


Lab3

plot

p1

# make a docker-compse.yml file contains the below code to make a container based on the dockerfile of the multistaging concept

version: '3.8'

services:
  node:
    container_name: remon-multistage-compose
    build: 
      dockerfile: Dockerfile-lab2-problem2-part2
    ports:
      - "5066:80"

# then run the following command

$ sudo docker compose up -d

# checked the localhost port 5066 and it is up and running

p2

# First creat a dir named with python-app-files and move app.py and requirements.txt into it # Create the docker file with below code

# get python base image
FROM python:3.7-alpine

# make a code dir and cd into it
WORKDIR /code

# set the enterypoit file  to the flask project   app.py
ENV FLASK_APP=app.py

# set the Host
ENV FLASK_RUN_HOST=0.0.0.0

RUN apk add --no-cache gcc musl-dev linux-headers

#copy requirments file to the container
COPY requirements.txt requirements.txt

# install the requirements
RUN pip install -r requirements.txt

# Flask listen on port 5000
EXPOSE 5000

#copy project files
COPY . .

# run the flask project 
CMD ["flask", "run"]

# then create the docker compose file also with the below code

version: "3.9"
services:
  web:
    build: .
    ports:
      - "8000:5000"
  redis:
    image: "redis:alpine"

# then run the following command

$ sudo docker compose up -d

# checked the localhost port 8000 and it is up and running

About

IMPORTANT FOR LEARNING

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 35.4%
  • JavaScript 33.2%
  • CSS 16.2%
  • Dockerfile 9.2%
  • Python 6.0%