Docker Images vs. Containers

Docker Images vs. Containers

IMAGE :- An image is an inert, immutable, file that’s essentially a snapshot of a container. Images are created with the build command, and they’ll produce a container when started with run. Images are stored in a Docker registry such as registry.hub.docker.com. Because they can become quite large, images are designed to be composed of layers of other images, allowing a miminal amount of data to be sent when transferring images over the network.

  • IMAGE ID is the first 12 characters of the true identifier for an image. You can create many tags of a given image, but their IDs will all be the same (as above).
  • VIRTUAL SIZE is virtual because its adding up the sizes of all the distinct underlying layers. This means that the sum of all the values in that column is probably much larger than the disk space used by all of those images.
  • The value in the REPOSITORY column comes from the -t flag of the docker buildcommand, or from docker tag-ing an existing image. You’re free to tag images using a nomenclature that makes sense to you, but know that docker will use the tag as the registry location in a docker push or docker pull.
  • The full form of a tag is [REGISTRYHOST/][USERNAME/]NAME[:TAG]. For ubuntu above, REGISTRYHOST is inferred to be registry.hub.docker.com. So if you plan on storing your image called my-application in a registry at docker.example.com, you should tag that image docker.example.com/my-application.
  • The TAG column is just the [:TAG] part of the full tag. This is unfortunate terminology
  • The latest tag is not magical, it’s simply the default tag when you don’t specify a tag.
  • You can have untagged images only identifiable by their IMAGE IDs. These will get the <none> TAG and REPOSITORY. It’s easy to forget about them.
  •  CONTAINER :- To use a programming metaphor, if an image is a class, then a container is an instance of a class—a runtime object. Containers are hopefully why you’re using Docker; they’re lightweight and portable encapsulations of an environment in which to run applications.

    • Like IMAGE ID, CONTAINER ID is the true identifier for the container. It has the same form, but it identifies a different kind of object.
    • docker ps only outputs running containers. You can view stopped containers with docker ps -a.
    • NAMES can be used to identify a started container via the --name flag.

    Automate Node Server with Docker and Gulp

    Automate Node Server with Docker

    To automate node server with using docker and gulp. first download the docker image for node server with following command

    docker pull sfvishalgupta/imagenode:v0
    

    Running the docker machine create the run.sh file with following code

    #!/bin/bash
    # setup app server
    echo 'Cleaning up previous docker images'
    docker rm -f nodeContainer
    service apache2 stop
    
    DIR=$( cd `dirname $0`/..; pwd )
    
    docker run -tid \
    	--name nodeContainer \
    	-p 80:3000 \
    	-v ${DIR}/:/var/www/html \
    	-v ${DIR}/bin/init.sh:/init.sh \
    	-w /var/www/html \
    	sfvishalgupta/imagenode:v0 \
        /init.sh
    
    docker ps
    

    Read more

    Docker Image

    Docker Image

    To create a new docker image first download the following file and remove .txt ext from file

    Dockerfile

    Now run the following command

    docker build -t sfvishalgupta/image:version .
    

    This command will automatically pick docker file or we can pass the docker file path inplace of dot
    now do docker commit and docker push.

    Working with Docker Some useful commands

    Docker Commands:-

    Following are some very useful docker commands for working with docker.

    #Pulling raw image from docker (latest ubuntu image) docker pull ubuntu #Listing all docker images available in local machine docker images #image ubuntu start running docker container named vcontainer with docker run –name vcontainer ubuntu /bin/bash #list out all running container docker ps -l #remove running container docker rm container_id #remove image docker rmi -f image_id #rename docker container docker rename old new #commit docker image docker commit -m “##message##” containterid imageid #push docker image on hub.docker.com docker push image

    * Remember don’t stop your docker container before pushing changes otherwise the changes will drop.

    Docker For Ubuntu

    Docker:-

    Docker is like a virtual Machine which we can setup for development and deployment. consider the different machine configurations for different PHP framework, like pimcore, zend, symphony. We can create a separate docker image each of these then we can share this image with team to work on it and at last we can deploy the same image on server, So we never need to worry about configuration for a project.

    Read more