1.To execute something inside of docker image
eg.
a. docker run busybox echo hi there
b. docker run busybox ls
but this will not work with the famous hello-world image
Reason -> it doesn't contain those program commands ie ls , echo ... it was just designed for the minimal way to print hello world
2. List all running dockers (presently running)
docker ps
so when we ran docker run hello-world kinda .. it immediately ran and turned off
3. to see all the dockers that ever ran on the machine
docker ps --all
Lifecycle
4. docker run = docker create + docker start
creating a container is equivalent to preparing the filesystem snapshot
to start we run to start-up command
executing them individually
1. docker create hello-world
returns a id --- > something like
sfsf4tre32423sdfsf
To run it
2. docker start -a id
id will the id we got when we created the docker
-a help to watch the output and print output in the terminal
by default docker start will not show u the output coming out from the container
When a container has stopped it doesnt mean that we cannot start it back again ...
To start a container back we can take its id
docker ps --all
will list id of all the dockers
docker start -a id
when we create docker with default command eg.docker run busybox echo hi there , then we cannot replace or remove the default command and will be executed whenever we run it
Removing stopped containers
docker system prune
will remove
a. stopped container
b. dangling images
c. cache
Logging
So let's assume that we started docker with -a and so we just have container id and don't know what happened inside so for that
docker logs <container id>
How to stop a running container
a. stop ( stops the process and can do a little bit of clean up eg.save file, generally equivalent to SIGTERM) .. will get some time to stop
b. kill (stop everything immediately, generally used when the stop is not responding . general equivalent to SIGKILL)
so,
docker stop <container-id>
example with Redis
How to run the 2nd command inside of a running container
To execute the additional command inside of a running container
docker exec -it <container id> <commands>
"-it" allows us to provide input to the container
if u dont use the about command will be executed but you will not get the ability to execute anything inside of it and get the terminal
Getting command prompt of the running container (one of the most useful command)
docker exec -it <container id> sh
sh helps to type command in the terminal
To get terminal when we start a container via run
docker run -it busybox sh
The downside of opening terminal with the run command is that we cannot execute another command with it and the command here is sh
To exit from shell use
ctrl+c / ctrl+d / exit
Container isolation
all container have their own file system so anything that you create in one will not be present in another container of the same image
To run a docker container in the background we use
docker run -d <image name>
eg.
a. docker run busybox echo hi there
b. docker run busybox ls
but this will not work with the famous hello-world image
Reason -> it doesn't contain those program commands ie ls , echo ... it was just designed for the minimal way to print hello world
2. List all running dockers (presently running)
docker ps
so when we ran docker run hello-world kinda .. it immediately ran and turned off
3. to see all the dockers that ever ran on the machine
docker ps --all
Lifecycle
4. docker run = docker create + docker start
creating a container is equivalent to preparing the filesystem snapshot
to start we run to start-up command
executing them individually
1. docker create hello-world
returns a id --- > something like
sfsf4tre32423sdfsf
To run it
2. docker start -a id
id will the id we got when we created the docker
-a help to watch the output and print output in the terminal
by default docker start will not show u the output coming out from the container
When a container has stopped it doesnt mean that we cannot start it back again ...
To start a container back we can take its id
docker ps --all
will list id of all the dockers
docker start -a id
when we create docker with default command eg.docker run busybox echo hi there , then we cannot replace or remove the default command and will be executed whenever we run it
Removing stopped containers
docker system prune
will remove
a. stopped container
b. dangling images
c. cache
Logging
So let's assume that we started docker with -a and so we just have container id and don't know what happened inside so for that
docker logs <container id>
How to stop a running container
a. stop ( stops the process and can do a little bit of clean up eg.save file, generally equivalent to SIGTERM) .. will get some time to stop
b. kill (stop everything immediately, generally used when the stop is not responding . general equivalent to SIGKILL)
so,
docker stop <container-id>
example with Redis
How to run the 2nd command inside of a running container
To execute the additional command inside of a running container
docker exec -it <container id> <commands>
"-it" allows us to provide input to the container
if u dont use the about command will be executed but you will not get the ability to execute anything inside of it and get the terminal
Getting command prompt of the running container (one of the most useful command)
docker exec -it <container id> sh
sh helps to type command in the terminal
To get terminal when we start a container via run
docker run -it busybox sh
The downside of opening terminal with the run command is that we cannot execute another command with it and the command here is sh
To exit from shell use
ctrl+c / ctrl+d / exit
Container isolation
all container have their own file system so anything that you create in one will not be present in another container of the same image
To run a docker container in the background we use
docker run -d <image name>
Comments
Post a Comment