containerization with docker

This is my first docker blog

why we use docker ?

it is use to launch the os within a seconds

which take hour of time in a simple

but by using docker command we used to launch the operating system.

The launched os are known as containers which have networking

with base system

we do with the help of aws cloud (ec2 service)

for ease of use.

Here is some basic commands of docker

log in to the root account as it have unlimited powers.

first of all if you want to use docker

you should install in your os either in virtual machine or

in aws cloud .

In case of virtual machine for example i am using redhat version 9

Installing Docker :- i have to configure yum then we use

yum install docker

systemctl status docker (showing status of docker whether it is running ,active or unactive)

To start the services of docker use:

systemctl start docker

now the docker services started

now to launch any os using docker we require image of that .

for see image and what requirements images needed visit hub.docker.com

To download image we have to use the docker

docker pull imagename:tag/version

To see that how many images exist in docker

docker images

use >>docker ps command to see the status of containers.

To launch os within the second use

docker run -i -t image:tag/imagename

-i –>interacting (it provides interface)

-t –> terminal

now the terminal or black screen of that os came

do what you want to do it is launched with in a second .

To see the attribute like -i -t see the manual of docker

use >>docker –help

REMOVING DOCKER IMAGES AND CONTAINER/ OS To remove any image file or runningos

use >>docker rmi image name (rmi-remove image)[to remove image]

for removing running os

either use >>docker stop container name or id [to check name use >>docker ps]

or use >>docker rm -f container name or id (-f is used to delete force fully any container or os)

To delete all the containers at one time :

first we have to learn about use of $

the value we put after $ it put the value of that

not understand don’t worry

for example :

x=5

echo x

x (it will print what you write)

and if >>echo $x

5 (the output will print on the screen)

so delete all container use:

docker rm -f $(docker ps -a -q)

docker ps -a -q (only provides all ids of container ) because of this it acts as a loop (rm -f) commands will forcefully remove all the containers running.

CONFIGURING HTTPD SERVER

docker run -it –name centos -p 8080:80 centos:7 [as we all have port number 80 we all are able to access webserver using 8080 port number]

-p = this is called as patting or in simple word to expose the webpages

–name (to give the name of container for ease of use)

we launch the centos through our base system

interface of centos came

install httpd to configure webserver

yum install httpd

To start the web server services use:

httpd

and your web server services started

But we access the web pages exist inside

/var/www/html [we also able to change this folder also after doing some setting]

use cd command to go inside a that folder

cd /var/www/html

create the file in the html format

To create file use either gedit filename.html and give your content if you are using in virtual machine then only it is useful because it shows graphical output

while using in cloud we don’t use gedit command as cloud doesn’t support

graphical command

but we run all command except that it not show graphical interface

in every os because every command came from some program and

every program belong to some program file

To know which program file that command exist

we use yum in case of ubuntu use apt-get command

yum whatprovides command name

it will provides the program file of that command

install that file to use that command using yum

so don’t use graphical command

so to make html file in cloud use cat command see how

cat > mayank.html (> it is used for pipeing as cat command is to read the content inside the file)

type the content

press ctrl+c

ls [to see whether the file exist or not ]

mayank.html

now you can see in your system by using public ip

docker compose to deploy application like word press

to install docker compose use

(curl -SL github.com/docker/compose/releases/download.. -o /usr/local/bin/docker-compose)

chmod +x /usr/local/bin/docker-compose (Making binary file executable )

now create a file in root and also create a directory through which you can mount the volume so that the data is not lost

mkdir /mycode

create the file in .yml format

vim filname.yml

version: "3.8"

services: db: networks:

  • mayanknet container_name: mydb image: mysql:latest volumes:
  • /database:var/lib/mysql environment:
  • MYSQL_ROOT_PASSWORD=redhat
  • MYSQL_DATABASE=tech
  • MYSQL_USER=mayank
  • MYSQL_PASSWORD=redhat wp: depends_on:
  • db networks:
  • mayanknet container_name: mywp image: wordpress:latest ports:
  • 8080:80 environment:
  • WORDPRESS_DB_HOST=mydb
  • WORDPRESS_DB_USER=mayank
  • WORDPRESS_DB_PASSWORD=redhat
  • WORDPRESS_DB_NAME=tech

networks: mayanknet: driver: bridge
:wq press enter

docker-compose up -d (to run the code inside the compose file in .yml) now type your publicip:port (in browser ) you willl get the interface of wordpress application