Getting familiar with Docker

Getting familiar with Docker

Subscribe to my newsletter and never miss my upcoming articles

Docker is an OpenSource containerization platform for Building, Shipping and Running applications using Container Virtualization technology. Docker packages all the dependencies in form of a Docker containers to ensure that our applicaton works seamlessly in any of the environment.

If you are not familiar with Docker and have not installed Docker in your device, you can go through my last article mentioning the installation here.

Docker Images

Docker uses the concept of Docker images to deploy the Docker Containers. Docker Images can be compaed with a template that can be used to create the Docker Containers. Docker Images are read-only templates. Docker Images are available on and can also be created by users.

Docker Process

Some Docker Commands

  1. docker search: Used to search for a particular image on DockerHub via command line.

    docker search IMAGE_NAME

    Screenshot from 2020-11-20 04-25-42.png

  2. docker pull: Used to pull images from DockerHub to Docker Engine for our use.

    docker pull IMAGE_NAME

    Screenshot from 2020-11-20 04-28-45.png

  3. docker images: Used to list all the available images on our Docker Engine.

    docker images

    Screenshot from 2020-11-20 04-28-58.png

  4. docker run: Creates the container and runs the default or specified command.

    docker run IMAGE_NAME
    docker run IMAGE_NAME COMMAND

    Screenshot from 2020-11-20 04-34-34.png

The life of a container is the running time of the command or code.

More about running Docker Containers

docker run command attaches and runs an image inside of a docker container. The docker run command requires one parameter and that is the image name.

docker run IMAGE_NAME
  • To run a specific command in Docker Container,
    docker run IMAGE_NAME COMMAND
  • To run a container with a specific name,
  • To run a container wth an interactive terminal,
    docker run -it IMAGE_NAME
  • To run a container in background,
    docker run -d IMAGE_NAME COMMAND
  • To delete a container as soon as it finishes it's execution,
    docker run --rm IMAGE_NAME COMMAND

The options with the docker run command can be coupled together and used accordingly.

Listing the Docker containers

docker ps: Used to list the docker containers.

docker ps

Screenshot from 2020-11-20 05-18-45.png

  • To list all the running docker containers,
    docker ps
  • To list all the docker containers, (weather running or stopped),
    docker ps -a
  • To list only the ID's of docker containers,
    docker ps -q

The options with the docker ps command can be coupled together and used accordingly.

Playing with Containers

  1. docker stop: Stops a container after closing all the running programs.

    docker stop CONTAINER_ID
    docker stop CONTAINER_NAME

    (Can be considered as properly shutting down the device)

  2. docker kill: Stops a container forcefully.

    docker kill CONTAINER_ID
    docker kill CONTAINER_NAME

    (Can be thought of forcefully stopping the device by removing the power cable)

  3. docker start: Used to start an existing stopped docker container.

    docker start CONTAINER_ID
    docker start CONTAINER_NAME
  4. docker exec: Used to run a child process along with the parent process.

    docker exec CONTAINER COMMAND
  5. docker rm: Used to remove a container from the memory. (Permanently delete)

    docker rm CONTAINER_ID
    docker rm CONTAINER_NAME
  6. docker rmi: Used to remove a pulled docker image.

    docker rmi IMAGE_NAME
Share this