docker run :

Docker run command is use to create a container from an image. when we run docker run < image-name >, docker-api sends this command to docker daemon which will create an instance of image (container) application into the docker host.

docker run is equivalent to the API /containers/create then /containers/(id)/start

First It will search the image from docker host system if it found then it will create a container otherwise it will go out to docker hub and pull the image. From second time onwards if we run the same image docker will find that in docker host system and won't go out to docker hub.

Run - Port Mapping : Publish or expose port

When we want to run multiple instance of a service or application we can use docker run with port(-p) option. which will create container on different ports of docker host sytem and mapped to container ip.

By using port mapping we can access the application outside of the host machine -- publically.

How to access application outside of the host machine.


data persistent in docker

When we stop or remove a container all the data inside it will be deleted.

If we want to keep the data even if the container is not active/alive then we need to mapped a directory outside of the conatainer and inside of docker host.

Create a directory inside of docker-host and mount the container volume

Get the details of a Container

Container logs :

docker run commnad with some useful options and arguments:

Name Syntax Description
Detached (-d) docker run -d IMAGE Run container in background.
--interactive, -i $ docker run -i IMAGE Keep STDIN open even if not attached.
-it docker run -it IMAGE attach with Terminal with interactive mode.
bash docker run -it IMAGE bash Open a command line tool and attach Terminal with interactive mode.
--expose, -p docker run -p [docker-host-port]:[container-port] image To publish the application/service globally.
--volume, -v docker run -v [dock-host/dir]:[cont./data/path] image-name To persistent the data in docker.

docker build commnad with some useful options and arguments:

Name Syntax Description
-t docker build . -t IMAGE Tag_Image_Name It will tag the image to Tag_Image_Name.