Docker


In this article, I have shared some basic commands in Docker. For developing, running and many more operations, Docker is an open-source platform. This will help you to get information containers that are running currently and also stopped containers.


Why do we use Docker in DevOps?
ans: In DevOps, containers help to give features like build, test, deploy, and many more pipelines.



How to start Docker in the terminal?

docker run -it ubuntu





How to check when ubuntu started?
 docker ps



How to check that all the images are downloaded to my local machine?
 docker images




How to download ubuntu?
docker run -it ubuntu



How to show all containers?
docker container ls


How to go inside a running container?
Note: bash shell should be attached to this running container.
This command will not work if your container isn't running.

command: docker container exec -it CONTAINER_ID



1st pic shows one container is already running:



2nd pic shows now we are in same container:

How to run mongo in docker?
docker run mongo







how to see all running and stopped containers?
command: docker ps -a




how to stop the container?
docker stop container_id





how to remove the container?
docker rm container_id




How to show all information regarding the container?
docker inspect CONTAINER_ID






How to check all logs?
docker logs container_id





How to delete all stopped containers?
docker container prune -f


How to run a container in the background?
docker run -d CONTAINER_NAME

Note: In the background, docker can run the container, and -d means detached mode.



How to directly put it in the terminal?
docker run ubuntu echo "Hello World"


How to check logs?
docker logs container_id

How to check logs for specifics?
 docker logs --since time container_id

 docker logs --since 5s a3c5
It will show the last 5 second's logs





How to install Nginx?
docker run nginx

How to run nginx using docker on the local system?
 docker run -d -p 8087:80 nginx

Note: this nginx is running on my local system right now.




How to share a container?

first, make some changes and then keep its container id. then exit and then run :

docker commit -m "message" container_id new_given_name

suppose I have given name names_ubuntu
docker commit -m "added names.txt file" 388dd2f309a8 names_ubuntu
Note: keep its id.






Note: above you can see the names.txt file.

How to see only the id of all containers?

 docker ps -q


HOW TO CREATE AN IMAGE?

STEPS:
1.


2.


3.

























Note:
all images you can find here: Docker Hub

















Comments

Popular posts from this blog

Jetpack Compose Modifier

Jetpack Compose Basics