DEV Community

Cover image for Docker Intermediate
Ragu
Ragu

Posted on • Updated on

Docker Intermediate

Source from Zeal Vora,KPLABS Course(Premium Instructor at Udemy)
Udemy

Zeal is one of my favorite author for docker. Please try to yourself 💖

(Tip: HE is ready to give some discount for students 😜)

Hi buddy, this is all are intermediate points. if you need to basic understanding please look at my previous docker beginner blog otherwise please ignore

-----------------Table of content-----------------

  1. Docker file

  2. COPY VS ADD

  3. EXPOSE

  4. HEALTH CHECK

  5. ENTRY POINT

  6. WORKDIR

  7. ENV

  8. TAG

  9. Docker commit

  10. layer of docker images

  11. Inspect

  12. Prune

  13. Flattening image

  14. Docker registry

  15. Apply the filters

16.Moving the image across the host

17.Build cache


1.Docker file

Every docker container based on images. Images based on docker files.

docker

Docker files contain the set of commands and microservice procedures. Docker file start FROM instructions its is a base image

FROM busybox
ENV NGINX 1.2
RUN touch web-$NGINX.txt
CMD ["/bin/sh"]
Enter fullscreen mode Exit fullscreen mode

** 2. COPY VS ADD **

Both command are copy the file from local to inside the container but depends on need it will change.

COPY = copy the files from local to inside the container
ADD = get the files from website like application zip files then
unzip the exact destination

COPY src dest
Enter fullscreen mode Exit fullscreen mode

** 3. EXPOSE **

Expose command used for port documentation. Its helps to where we are going to run the port.so clear about the port mapping

docker

EXPOSE port-no
Enter fullscreen mode Exit fullscreen mode

4. HEALTH CHECK

Health check is testing our application healthy or not. Its check some argument and true or false condition.
Condition is true application is healthy whether condition is false application is un-healthy

docker

HEALTHCHECK --interval=35s --timeout=4s CMD curl -f https://localhost/ || exit 1
Enter fullscreen mode Exit fullscreen mode

5. ENTRY POINT

In Docker files, an ENTRYPOINT instruction is used to set executables that will always run when the container is initiated. Unlike CMD commands, ENTRYPOINT commands cannot be ignored or overridden—even when the container runs with command line arguments stated

Once container is start we will give the dynamic command options in entry point section

ENV name Darwin
ENTRYPOINT ["/bin/echo", "Welcome, $name"] 
Enter fullscreen mode Exit fullscreen mode

6. WORKDIR

Containers default working directory is called WORKDIR. once execute the container we launch directly in which one we mention the WORKDIR argument.

WORKDIR destination
Enter fullscreen mode Exit fullscreen mode

7. ENV

ENV is a similar like system environment variable. Its works like key and value pair options inside of the container. We pass the dynamic value instead of ENV.

ENV command
Enter fullscreen mode Exit fullscreen mode

8. TAG

Tag the image for reference. Help to improve the image information and maintenance

tag image-id tag-name
Enter fullscreen mode Exit fullscreen mode

9. Docker commit

clone the running docker container for version maintenance and reusability.

docker commit container-id
Enter fullscreen mode Exit fullscreen mode

10. layer of docker images

Docker is the layer architecture so each docker file line represent the layer.Layer have a unique information

docker

*11. Inspect *

Docker image have a lot of information include date,command,size and os architect see the all info associate with the docker image.

docker inspect
Enter fullscreen mode Exit fullscreen mode

12. Prune

Clean-up the dangling and unused images with prune.It's helps to reduce the unused images and increase the system memory.

docker prune
Enter fullscreen mode Exit fullscreen mode

12. Flattening image

Use to create the single layer image.Its helps to manage the storage.single layer of image and fulfill the all requirement

FROM debian:wheezy WORKDIR /tmp RUN wget -nv http://centurylinklabs.com/someutility-v1.0.0.tar.gz && \ tar -xvf someutility-v1.0.0.tar.gz && \ mv /tmp/someutility-v1.0.0/someutil /usr/bin/someutil && \ rm -rf /tmp/someutility-v1.0.0 && \ rm /tmp/someutility-v1.0.0.tar.gz

Enter fullscreen mode Exit fullscreen mode

13. Docker registry

docker

Its help to maintain the image version in repository.similar to github method.we have two option private and public repository. push pull and tag in options are available with repository.

15. Apply the filters

Public repository have a so many options in images.official and unofficial image options are available so filiter help to getting the exact image option.

docker search image name
Enter fullscreen mode Exit fullscreen mode
--filter , -f       Filter output based on conditions provided
--format        Pretty-print search using a Go template
--limit number          Max number of search results
--no-trunc      Don't truncate output
Enter fullscreen mode Exit fullscreen mode

16.Moving the image across the host

It helps to move the image one environment to another one.
first archive and load the file then move the tar file.

docker save myapp > myapp.tar
docker load < myapp.tar
Enter fullscreen mode Exit fullscreen mode

17.Build cache

Already we discuss docker is the layer architecture so each and every layer have a individual build structure .

Rebuild the same images multiple times that time docker refer to the cache. its save the build time.rather than we add the new step for same docker image that time only docker build again.

docker

Top comments (0)