docker run :
Docker run command is use to run the 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.
First It will search the image from docker host system if it found then it will create an 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.
- Options with Run command.
-d (deteched mode) : it will run the conatainer on background.
attach < container_id/name: it will attach the background running job to the foreground.
# Syntax :
$ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
# Examples :
docker run nginx
docker pull <Image NAME>:
Docker pull command will download an image and store it on our host machine.
# Syntax :
docker pull nginx
docker ps :
Docker ps command list all the running container along with some basic information such as CONTAINER ID, IMAGE, COMMAND, CREATED, STATUS, PORTS and NAMES. CONTAINER ID and NAMES are automatically created by docker.
docker ps -a :
Docker ps -a command list all the running container as well as the stopped or existed container.
# Syntax :
docker ps
docker ps -a
docker stop <CONTAINER ID/NAMES>:
Docker stop command will stop a running container.
# Syntax :
docker stop nginx
docker rm <CONTAINER ID/NAMES>:
Docker rm command will remove a stopped or existed container permanently.
# Syntax :
docker rm nginx
docker images :
Docker images command will list all the available images from host along with some basic information such as REPOSITORY, TAG, IMAGE_ID, CREATED and SIZE.
# Syntax :
docker images
docker rmi <Image NAME>:
Docker rmi command will remove a stopped or existed container permanently.
We need to make sure that all the depedent conatainers are deteled before removing the image.
# Syntax :
docker rmi nginx
docker exec < container_id/name >:
Docker exec container_name will allow us to run the command into the conatainer.
If we want to perform any task with-in the container such as view/edit/print the content of a file, run the specific job inside container, we can use exec command.
# Syntax :
docker exec < container_id/name > cat /filename/to/print