Docker

Docker

Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers.

Containers are instances of image

Containers are layers of images, mostly linux and application layer on the top.

Image is a file used to execute code in container with all libraries, dependencies, and config files that the container needs to run for that image.

VM vs Docker

  1. Each VM runs its own OS-kernel. All DOCKER containers share same OS-kernel of the host. (kernel- storage,memory)
  2. VM boot up time is in minutes due to its own kernel. DOCKER initiates in seconds.
  3. VM- no version control, DOCKER- images can be versioned like github.
  4. VM- can run few VMs at a time on laptop, DOCKER- multiple containers can run at a time.

Ports of local host and port of container

We cannot bind or open two same ports of host machine with container's port. Although we can bind two different port of host machine with same container's port.

Docker commands-

docker pull, docker run redis:4.0, docker start, docker stop, docker -d (run container in detached mode), docker -p6000:6379 (bind port of host to port of container),

docker ps -a (list all used container on your host), docker image (list all images on host), docker logs,

docker run -d -p6000:6379 --name Shivani-test2 redis:7.0 (rename container)

docker logs {containerid} | tail

we can steam logs to view latest log change by- docker logs {container id} -f

Trobuleshoot /Debug app file in container using executable cmd

"docker exec -it Shivani /bin/bash" or "docker exec -it {{container id}}} /bin/sh"

(run executable interactive terminal cmd to get into directory of application), futher cd, ls, env, exit cmds can be used to make changes to file.

Docker run VS Docker start

Docker run- we create new container to pull and run images (latest or any version)

Docker start- we work with existing container not images (start or stop container)