From 195db7a103ee8b01d2b2de34f013744adc2732a2 Mon Sep 17 00:00:00 2001 From: apuzyrevsky Date: Wed, 15 Jan 2020 20:08:11 +0200 Subject: [PATCH] Update README.md added several answers for the Docker section. --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2a2e95e..11eb790 100644 --- a/README.md +++ b/README.md @@ -2522,11 +2522,13 @@ Docker daemon redirects output from container to Docker CLI which redirects it t
How do you run a container?
+ docker run
What `docker commit` does?. When will you use it?
+ Create a new image from a container’s changes
@@ -2551,6 +2553,7 @@ Create a new image from a container’s changes
How do you remove old, non running, containers?
+ 1. To remove one or more Docker images use the docker container rm command followed by the ID of the containers you want to remove. 2. The docker system prune command will remove all stopped containers, all dangling images, and all unused networks 3. docker rm $(docker ps -a -q) - This command will delete all stopped containers. The command docker ps -a -q will return all existing container IDs and pass them to the rm command which will delete them. Any running containers will not be deleted. @@ -2560,11 +2563,13 @@ Create a new image from a container’s changes
What is Dockerfile
+ Docker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.
What is the difference between ADD and COPY in Dockerfile?
+ COPY takes in a src and destination. It only lets you copy in a local file or directory from your host (the machine building the Docker image) into the Docker image itself. ADD lets you do that too, but it also supports 2 other sources. First, you can use a URL instead of a local file / directory. Secondly, you can extract a tar file from the source directly into the destination. Although ADD and COPY are functionally similar, generally speaking, COPY is preferred. That’s because it’s more transparent than ADD. COPY only supports the basic copying of local files into the container, while ADD has some features (like local-only tar extraction and remote URL support) that are not immediately obvious. @@ -2572,6 +2577,7 @@ Although ADD and COPY are functionally similar, generally speaking, COPY is pref
What is the difference between CMD and RUN in Dockerfile?
+ RUN lets you execute commands inside of your Docker image. These commands get executed once at build time and get written into your Docker image as a new layer. CMD is the command the container executes by default when you launch the built image. A Dockerfile can only have one CMD. You could say that CMD is a Docker run-time operation, meaning it’s not something that gets executed at build time. It happens when you run an image. A running image is called a container. @@ -2585,8 +2591,8 @@ A common answer to this is to use [hadolint](https://github.com/hadolint/hadolin
Explain what is Docker compose and what is it used for
- -Docker Compose is used for running multi-container applications + +Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.
@@ -2610,10 +2616,16 @@ Swarm management which means you can create new swarms in Docker Cloud.
Where Docker images are stored?
+In DockerHub
Explain image layers
+ +A Docker image is built up from a series of layers. Each layer represents an instruction in the image’s Dockerfile. Each layer except the very last one is read-only. +Each layer is only a set of differences from the layer before it. The layers are stacked on top of each other. When you create a new container, you add a new writable layer on top of the underlying layers. This layer is often called the “container layer”. All changes made to the running container, such as writing new files, modifying existing files, and deleting files, are written to this thin writable container layer. +The major difference between a container and an image is the top writable layer. All writes to the container that add new or modify existing data are stored in this writable layer. When the container is deleted, the writable layer is also deleted. The underlying image remains unchanged. +Because each container has its own writable container layer, and all changes are stored in this container layer, multiple containers can share access to the same underlying image and yet have their own data state.