Wednesday, November 29, 2023

Docker File PYTHON Installation

 We need to create three files 

1 vi requirements.txt

2 py.dockerfile

3 index.py


Write the following code in the requirements.txt

 vi requirements.txt


flash
boto
redis

Write the following code in the py.dockerfile




FROM python:alpine3.7

COPY . /app

WORKDIR /app

RUN pip install -r requirements.txt

EXPOSE 5000

CMD python ./index.py


Write the  following code in the index.py

 vi index,py

from flash import Flash
app= Flash(__name__)
@app.route("/")
def hello()l
     return "Hello world!"
if __name__==  "__main__":
    app.run(host="0.0.0.0", port=int("5000"), debug=True)

Finally run the docker build command

docker build -f py-dockerfile . -t hello-python:2.2
























Now, run the docker

docker run  -dit --name hello-py -p 5000:5000 hello-python:2.2

to keep running in the foreground use this command

docker run  -dit --name hello1-py -p 5000:5000 hello-python:2.2 tail -f















Tuesday, November 28, 2023

Docker 13 (Docker File)

 





Creating a docker file 

#This is a sample Image

FROM ubuntu

MAINTAINER DevOps-Team

RUN apt-get update

RUN apt-get install tzdata

EXPOSE 80

CMD [“nginx","-g","daemon off;"]


Next step is build

docker build -f dockerfile . --tag nginx123:1.23



















Let me run the docker File

docker run -idt --name 007 -p 80:80 nginx123:1.23

Let me  verify








You will be able to see that nginx service is started automatically





You can run by using the public ip address
























Sunday, November 26, 2023

Docker 12 (Docker File )

A Dockerfile is a text document that contains commands that are used to assemble an image. We can use any command that call on the command line. Docker builds images automatically by reading the instructions from the Dockerfile.

If we use the Docker images command, we can see the existing images in our system. But Docker also gives you the capability to create your own Docker images, and it can be done with the help of Docker Files

 A Docker File is a simple text file with instructions on how to build your images.


The docker build command is used to build an image from the Dockerfile. You can use the -f flag with docker build to point to a Dockerfile anywhere in your file system.






Note: It is text file and saved without any extension. We can also say that it is text file, which is composed of various commands and arguments listed to automatically perform action on base image in order to get the new one.







Dockerfile Instructions















Docker Engine, will pick the Docker file , and it generated the Docker Image, once the Docker Image is created. It will create a container, and from there we are pushing that code to Docker Hub. From there to Staging Server / Production Server.



Step 1 − Create a file called Docker File and edit it using vim. Please note that the name of the file has to be "Dockerfile"

And all the commands should be in capital Letter.

Step 2 − Build your Docker File using the following instructions.

Note: All the commands should be in newline only.

    Add : Add command is nothing but the copy Command.

    CMD, Entry point are basically the container commands. These are the     two commands , which always comes at the End.

    ENV- Environment Variables.
    EXPOSE: We can declare the port Number using export command.
#This is a sample Image 
FROM ubuntu  (It is used to define the base Image)
MAINTAINER demousr@gmail.com 

RUN apt-get update 
RUN apt-get install –y nginx 
CMD [“echo”,”Image created”] 
Explanation: 
  • The first line "#This is a sample Image" is a comment. You can add comments to the Docker File with the help of the # command

  • The next line has to start with the FROM keyword. It tells docker, from which base image you want to base your image from. In our example, we are creating an image from the ubuntu image.


  • The next command is the person who is going to maintain this image. Here you specify the MAINTAINER keyword and just mention the email ID.


  • The RUN command is used to run instructions against the image. In our case, we first update our Ubuntu system and then install the nginx server on our ubuntu image.


  • The last command is used to display a message to the user.


  • Step 3

  • Save the file. In the next chapter, we will discuss how to build the image.


  • Interview question:

  • Docker Hub is a registry service on the cloud that allows you to download Docker images that are built by other communities. You can also upload your own Docker built images to Docker hub























Add Command















Example:








































Example:
























Next Run, the below Command

docker build -f dockerfile . --tag myimageu















Now, the image is created successfully.











To check layers in the newly created image














Difference between Run and Command :


Run command will not have a shell. That command will execute there only. A  Dockerfile can have many RUN steps that layer on top of one another to build the image.

CMD will go inside a running container of that image. CMD Command will execute only one service.

To address the above point, Docker has come with the ENTRY POINT--> It will go inside the container and start services.

Add Vs Copy

First, the ADD directive can accept a remote URL for its source argument. The COPY directive, on the other hand, can only accept local files.



Friday, November 24, 2023

Docker 11

Revise again with few more commands. learning port number assigning and other things

First step, creating a container by running the below command

 docker run -itd --name con2 ubuntu:18.04







Next step , is we need to login inside the container.







































Why the container got stopped Now. 

The reason, is when ever we are running use bash command, a new processor will be created, and when we select exit . it is going to kill that processor.







Now, you can see only one process will be running






























Ctrl p q Combination





















Let me map to the port














Next let us install Apache inside newly created container



















Docker 10

 docker top

With this command, you can see the top processes within a container.                       

Syntax docker top ContainerId

docker attach

This command is used to attach to a running container.

docker attach ContainerID 

Docker - Configuring



service docker stop

This command is used to stop the Docker daemon process.

Syntax: service docker stop 

service docker start

This command is used to start the Docker daemon process.

Syntax: service docker start


Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...