Docker Imp points

  1. docker run -it <image> <any command like ls>

 - It will start the container execute the command and stop the container.The status of the stopped container can be seen using docker ps -a

2. docker run -it --rm <image> <any command like ls>

- It will do the same the same hing, but after stopping it will also kills the container

3. If we run an docker image without specifying -d(detached mode),then we will enter into container directly and if we exit the container will be stopped

4.If we run container in detached mode by specifying -d,as shown below image will run in background,we can connect to it using exec.

Eg:$docker run -itd <image>

5. About user in docker file:

- If we specify any user in dockerfile, all the commands will be executed by that user and in  the image that user is retained, i.e if you make a container out of it,we will get same user.

- If we want to switch user,you can do so using another user instruction in docker file and the finalowner of the docker image is the user which is created last in docker file

- Before using any user, the user should be created in container, or you can use already created user, which you can see in /etc/passwd folder.

6. All the instrucions after the workdir are only executed in work dir folder and we can switch as many work dirs as we can, when we connect to container(using run or exec) we will always land on workdir which was used last in docker file

7.COPY and ADD,difference is copy just copies files from host machine to container,while ADD also does the same..But if we wqant to copy so many files..Then we can archieve it in xip or tar.gz format and use ADD,it by default extracts and theconnects of archives.

8.ENV and ARG, they are just like varaiables, but if we want to retains those values inside a running container which we make out of docker image then we need to use ENV.If we want to use its values only in the docker file,then we can go for ARG 

9.If you want to push the image created by you to registry,lets say docker hub,after docker login,we need to give tag name as below:

Eg:Lets say image name on my local host machine is myimage and tag name  is 2, and i want to push it to docker hub and my user name is myuser and imagename in need to use is myupdatedimage and tag is 3 in docker hub

Step 1:

$docker login

step 2:

$docker tag myimage:2 myuser/myupdatedimage:3

step 3:

$docker push myuser/myupdatedimage:3

10. docker exec executes a new command / create a new process in the container’s environment, while docker attach just connects the standard input/output/error of the main process(with PID 1) inside the container to corresponding standard input/output/error of current terminal(the terminal you are using to run the command).

11.There is one behavior that is different between -v and --mount when using docker bind mounts:z

If you use -v or --volume to bind-mount a file or directory that does not yet exist on the Docker host, -v creates the endpoint for you. It is always created as a directory.

If you use --mount to bind-mount a file or directory that does not yet exist on the Docker host, Docker does not automatically create it for you, but generates an error.

12. Containers connected to the default bridge network can communicate, but only by IP address, unless they are linked using the legacy --link flag, but containers in user defined bridge network can communicate with container names

13.To filter docker inspect result,which is in json format

 docker inspect --format='{{.Os}}' nginx
14.  Install docker  Rhel and Centos using scripts: here

Comments

Popular posts from this blog

Docker volumes backup and restore & Docker networks