And then, it only performs the steps after that i.e. Instead of running all the commands every time you re-build an Image, Docker detects which was the first step that changed. This is because - Docker caches the steps which form a stack of layers. You should notice that it’s much faster this time. You can verify that by running the build command again. Now the cool thing is, if you have already built the Image before, any consecutive builds to that Image will be much faster.
#How does docker on mac work apk
to use the files in the current directory in building the Image. specifies the current directory as the PATH for the build context i.e. Now, to create an Image from the Dockerfile, we can run - docker build -t my-app. Let’s create a simple shell script for our demo which prints the datetime every 2 seconds - #!/bin/sh while true do echo "hi! what time is it?" echo "it is - `date`" sleep 2 done NOTE: Alpine is Linux distribution like Ubuntu or Fedora, but it is SUPER lightweight. run the /app/my-app.sh shell script when the container is started.copy files from the current directory of the host (in this case your computer) to the /app folder inside the container.
#How does docker on mac work update
If you’re on windows, I suggest opening up git-bash. To follow along, open up your terminal and create a new directory to work with. Since examples are an excellent way to understand concepts, let’s have our own! But in most cases, it is built using a Dockerfile where the commands to be run are specified in code, and thus, can be automated. That task could be to run a web server or to run a cron job or send an email or whatever you can make a computer do.Īn Image can be built manually by running the commands step-by-step against the Docker daemon. Let’s uncover the black box… How Docker Images workĪ Docker Image specifies a sequence of steps required to perform a particular task. You already know this in much more detail if you have gone through the first blog.īut how do Images actually work? It seemed like magic to me when I had started out.
Virtualization gives us the ability to create virtual environments from a single physical machine or computer. Just to help us clarify the main concepts, let’s start by recalling that…ĭocker is a platform that allows us to package our applications into deployable executables - called containers, with all its necessary OS libraries and dependencies.Ī Docker Image is a blueprint or template for creating Docker Containers.ĭocker Containers are processes that enable OS-level virtualization.