Sunday 31 July 2016

docker run -d

Docker run command is used to create a docker container out of docker images. This tutorial is to tell ways to create docker container in detached mode.

So, the first question that came in the mind is what is detached mode. Detached mode means that the when the root process of the host machine on which docker engine is installed exits, the docker container started in detached mode also exits.

How to start docker container in detached mode?

docker run -d=true 
docker run -d
You can start the docker container in detached mode using -d=true (or simply -d) options with docker run interface. 

By default, the docker container starts in foreground mode.

Points to remember when docker container is started in detached mode:

(a) Docker container will not automatically be removed when you stop the container.
(b) Don't start container in detached mode using unix service command. The problem it will face here is that unix service process returns (and exits), so the container will also stop in detached mode due to this.

Saturday 30 July 2016

Docker Container Interview Questions

Docker is a new technology for virtualization. Here are some interview questions and answers on docker container.


How to create docker container?

We can create docker container by running this command
docker run -t -i <image name> <command name>
This will create and start the container


How do you create docker image?

Docker image are created using Docker file. Docker build is command to create docker image out of docker file


So you have the docker image, what is the next step?

With docker image, we can spawn as many containers as needed. All containers can be same instance or it can also be different instance, what I mean that if we are using the same command for creating multiple containers, all container will behave as same. However, if you choose different command to create container out of same image, it will provide different functionality altogether.


How to know the container status?

Just fire docker ps -a to list out all running container with stauts (running or stopped) on a host

How to stop and restart the container?

To stop container, we can use docker stop <container id>
To start a stopped container, docker start <container id> is the command
To restart a running container, docker restart <container id>