Saturday, 22 July 2023

How to create docker image

 1. keep your code ready

2. write docker file:

Dockerfile

# downloaded base image
FROM python:3.8-alpine
# copied code from current location to app folder inside docker
COPY . /app
# redirecting to app folder inside docker
WORKDIR /app
# install all libraries inside your docker
RUN pip install -r requirement.txt
# running the final Python code
CMD python app.py


3. download the docker desktop on your computer
4. in the command prompt go to the location of dockerfile and run
    1. to create a docker image
    docker build -t <docker image name> .
    #example => docker build -t first-docker-image .

    2. to see existing docker images
    docker images

    3. to run the created docker image
    docker run -p <port>:<port> <image name>
    #example => docker run -p 5000:5000 first-docker-image

    here once you run, you get two ip address, one is your localhost address and another one is docker image ip address that will not work on our local computer. so take computer localhost to run

    4. to see all running docker images
    docker ps

    5. to stop the running docker image
    docker stop <container name>

    6. to delete the existing docker image
    docker image rm -f <docker image name>
    #example => docker image rm -f first-docker-image

    7. to change docker image name
    docker tag <current name> <new name>
    docker tag first-docker-image first-docker-image-1

    8. to push your docker image to repository
        login to docker
        1. docker login
        2.  docker push <image name>:<version>
        #example => docker push first-docker-image-1:latest
        now your image will be visible on the repository

    
    9. pull any image from docker
        docker pull <image name>:<tag> 
        #example => docker pull first-docker-image-1:latest

Thursday, 2 March 2023

how to clone repo using ssh

1. Generate public key
To generate public key 1st install the github and in the github terminal type 
ssh-keygen -t rsa -b 2048
It will store your public key in the default folder. It will show you folder name where it has stored. 
2. Add public key in github :
To add open github and on profile picture click and go to preference > ssh keys

And here give title and copy .pub ssh key and paste it here. 

3. Now you'll be able to pull and push the changes in github