Skip to main content

Docker commands summary person notes

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>

Comments

Popular posts from this blog

opening multiple ports tunnels ngrok in ubuntu

Location for the config yml file /home/example/.ngrok2/ngrok.yml content of config file authtoken: 4nq9771bPxe8ctg7LKr_2ClH7Y15Zqe4bWLWF9p tunnels: app-foo: addr: 80 proto: http host_header: app-foo.dev app-bar: addr: 80 proto: http host_header: app-bar.dev how to start ngrok with considering the config file: ngrok start --all

rename field in elastic Search

https://qiita.com/tkprof/items/e50368eb1473497a16d0 How to Rename an Elasticsearch field from columns: - {name: xxx, type: double} to columns: - {name: yyy, type: double} Pipeline API and reindex create a new Pipeline API : Rename Processor PUT _ingest/pipeline/pipeline_rename_xxx { "description" : "rename xxx", "processors" : [ { "rename": { "field": "xxx", "target_field": "yyy" } } ] } { "acknowledged": true } then reindex POST _reindex { "source": { "index": "source" }, "dest": { "index": "dest", "pipeline": "pipeline_rename_xxx" } }

Sumeru enterprise tiger privacy policy

Sumeru Enterprise Tiger Business Solutions Pvt. Ltd. Data Privacy Policy At Sumeru Enterprise Tiger Business Solutions Pvt. Ltd. we are committed to providing you with digitalization software products and services to meet your needs. Our commitment includes protecting personally identifiable information we obtain about you when you register to use one of our websites or become our customer (“Personal Information”). We want to earn your trust by providing strict safeguards to protect your Personal Information. This Policy applies to members, customers, former customers, users, and applicants. In the course of our business activities, Sumeru Enterprise Tiger Business Solutions Pvt. Ltd. collects, processes, and shares Personal Information. Indian law gives individuals the right to limit some but not all sharing. This Policy explains what Personal Information we collect, process, and share. We describe how we do so, and why. The Policy also describes your rights to access a...