Docker is a company that made containers popular. However, container technology existed before Docker. FreeBSD, LXC, and Warden are early container technology. Docker appeared in 2013 and has become quite popular. However, new container runtimes have appeared since Docker’s introduction; for example runc, containerd, Podman, CRI-O, and OCI? containers?
Two important components? to understand about Docker technology:???????
i) Client CLI tool is used to execute instructions to the Docker runtime at the command line
ii) Container runtime is to create containers and run them on the operating system.
- Dockerfile: Dockerfile is a text file that Docker reads from top to bottom. It contains a bunch of instructions that inform Docker HOW the Docker image should get built or Dockerfile is a? blueprint for building Docker images.
- Docker Image: Docker image is a file used to execute code in a Docker container. Docker images act as a set of instructions to build a Docker container ot a non-running container.?
- Docker Container: Docker container is a running instance of a Docker image or ? A container is a collection of one or more processes, organized under a single name and identifying ID that is isolated from the other processes running within a computing environment.?
The key difference between a Docker image v/s a container is that a Docker image is a template that defines how a container will be realized and a Docker container is a runtime instance of a Docker image.
The following is an explanation of each line in the Dockerfile, Containers, and images :
- The Dockerfile, as shown above in Image, declares node:15.4.0-alpine3.10 as the base image.
- The Dockerfile has instructions to declare a working directory, /app
- Docker copies all the files for the application in the current directory of the developer’s file system into the working directory, /app.
- The Dockerfile tells the Docker runtime to execute npm install in order to download the dependency packages that are associated with the application.
- The Dockerfil tells the runtime to expose port 3000.
- Finally, the Dockerfile tells the runtime to start up the application by executing the command, node index.js.
- Docker image creation ?command: ?docker build -t=image_alpine:3.10 ??
docker is the CLI command
- build is the subcommand used to create the image based on the Dockerfile
- -t=an_image is a parameter that indicates the tag of the image, e.g. tag as a way to identify an image.
- ?. ?is a period that indicates that the Dockefile upon which to implement the build is in the current directory. If the Dockerfile is elsewhere, you provide the path to the Dockerfile instead of the period.
?After a container image is created, you use the subcommand, run to realize the container against the Dockerfile.?
The following is an example of using the subcommand. docker run -d name myalpinecoantiner -p 3000:3000 image_alpine:3.10
- docker is the CLI command
- run is the subcommand used to create the container based on the container image
- -d is a parameter that tells the container runtime to run the container in the background so as not to tie up the terminal window in which run is being created
- –name mycontainer is a parameter that gives the container a name, in this case, mycontainer. Also, the container will be assigned a unique identifier by the container runtime
- -p 3000:3000 is a parameter that tells the container runtime to bind the port 3000 on the local machine to port 3000 from the running container
- Image_alpine:3.10 ?declares the docker image to use. The Docker runtime will look on the local machine first to locate the image. If the container image is not on the local machine, Docker will look on the default container registry for the image. The default container registry is usually DockerHub.
To verify that the container is running, type the following command in a terminal window:
You’ll get results similar to the following:
CONTAINER ID ? IMAGE ? ? COMMAND? ? ? ? ? CREATED? ? ? ? STATUS ? PORTS? ?NAMES
16126511090f ? ? image_alpine:3.10 ? "node server.js"? 8 seconds ago ? ? Up 6 seconds? 0.0.0.0:3000->3000/tcp? ? ? myalpinecontainer
Senior Director - Partners Business -Lead WW GSIs - Programs and India Partner Sales
2 年Thanks for sharing Taradutt Pant
Director Strategic Initiatives | Cyber Security Evangelist
2 年The key difference between a Docker image v/s a container is that a Docker image is a template that defines how a container will be realized and a Docker container is a runtime instance of a Docker image.