Docker
Docker
Code Issues 10 Pull requests 32 Discussions Actions Projects Wiki Security Ins
[Link] 1/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
Figure: Docker Vs VM Below are list of 6 difference between Docker container & VM:
[Link] 2/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
Yes, you can run multiple processes inside Docker container. This approach is discouraged for most use cases. For
maximum efficiency and isolation, each container should address one specific area of concern. However, if you need
to run multiple services within a single container, you can use tools like supervisor. Supervisor is a moderately
heavy-weight approach that requires you to package supervisord and its configuration in your image (or base your
image on one that includes supervisord), along with the different applications it manages. Then you start
supervisord, which manages your processes for you. Example: Here is a Dockerfile using this approach, that assumes
the pre-written [Link], my_first_process, and my_second_process files all exist in the same directory as
your Dockerfile.
What is DockerHub?
DockerHub is a cloud-based registry service which allows you to link to code repositories, build your images and
test them, stores manually pushed images, and links to Docker cloud so you can deploy images to your hosts. It
provides a centralized resource for container image discovery, distribution and change management, user and team
collaboration, and workflow automation throughout the development pipeline.
What is Dockerfile?
Docker builds images automatically by reading the instructions from a text file called Dockerfile. It contains all
commands, in order, needed to build a given image. A Dockerfile adheres to a specific format and set of
instructions which you can find here.
Yes. Yaml is a superset of json so any JSON file should be valid Yaml. To use a JSON file with Compose, specify the
filename to use, for example: docker-compose -f [Link] up
You can use json instead of yaml for your compose file, to use json file with compose, specify the filename to use for
eg: docker-compose -f [Link] up
This command will create and start a [Link] you want to verify the list of all running container with the status
on a host use the below command:
$ docker ps -a
Using a JSON configuration file. This is the preferred option, since it keeps all configurations in a single place.
Using flags when starting dockerd. You can use both of these options together as long as you don’t specify the
same option both as a flag and in the JSON file. If that happens, the Docker daemon won’t start and prints an
error message. $ dockerd --debug --tls=true --tlscert=/var/docker/[Link] --
tlskey=/var/docker/[Link]
--host tcp://<Host_IP>:2376
[Link] 4/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
15. Can you list reasons why Container Networking is so important? Below are top 5 reasons why we need
container networking:
CNM refers to Container Networking Model. The Container Network Model (CNM) is a standard or specification
from Docker, Inc. that forms the basis of container networking in a Docker [Link] is Docker’s approach to
providing container networking with support for multiple network drivers. The CNM provides the following contract
between networks and containers:
All containers on the same network can communicate freely with each other
Multiple networks are the way to segment traffic between containers and should be supported by all drivers
Multiple endpoints per container are the way to join a container to multiple networks
An endpoint is added to a network sandbox to provide it with network connectivity
Network,
Sandbox and
Endpoint. Sandbox is a generic term that refers to OS specific technologies used to isolate networks stacks on a
Docker host. Docker on Linux uses kernel namespaces to provide this sandbox functionality. Networks “stacks”
inside of sandboxes include interfaces, routing tables, DNS etc. A network in CNM terms is one or more
endpoints that can [Link] endpoints on the same network can communicate with each
[Link] 5/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
Docker’s networking subsystem is pluggable using drivers. Several drivers exist by default, and provide core
networking functionality. Below is the snapshot of difference of various Docker networking drivers.
Below are details of Docker networking drivers: Bridge: The default network driver. If you don’t specify a driver, this
is the type of network you are creating. Bridge networks are usually used when your applications run in standalone
containers that need to communicate.
Host: For standalone containers, remove network isolation between the container and the Docker host, and use the
host’s networking directly. host is only available for swarm services on Docker 17.06 and higher.
Overlay: Overlay networks connect multiple Docker daemons together and enable swarm services to communicate
with each other. You can also use overlay networks to facilitate communication between a swarm service and a
standalone container, or between two standalone containers on different Docker daemons. This strategy removes
the need to do OS-level routing between these containers. See overlay networks.
MacVLAN: Macvlan networks allow you to assign a MAC address to a container, making it appear as a physical
device on your network. The Docker daemon routes traffic to containers by their MAC addresses. Using the macvlan
driver is sometimes the best choice when dealing with legacy applications that expect to be directly connected to
the physical network, rather than routed through the Docker host’s network stack.
None: For this container, disable all networking. Usually used in conjunction with a custom network driver. none is
not available for swarm services.
[Link] 6/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
In terms of networking, a bridge network is a Link Layer device which forwards traffic between network segments. A
bridge can be a hardware device or a software device running within a host machine’s kernel. In terms of Docker, a
bridge network uses a software bridge which allows containers connected to the same bridge network to
communicate, while providing isolation from containers which are not connected to that bridge network. The
Docker bridge driver automatically installs rules in the host machine so that containers on different bridge networks
cannot communicate directly with each other.
You can specify the subnet, the IP address range, the gateway, and other options. See the docker network create
reference or the output of docker network create --help for details.
Use the docker network rm command to remove a user-defined bridge network. If containers are currently
connected to the network, disconnect them first.
When you create a new container, you can specify one or more --network flags. This example connects a Nginx
container to the my-net network. It also publishes port 80 in the container to port 8080 on the Docker host, so
external clients can access that port. Any other container connected to the my-net network has access to all ports
on the my-nginx container, and vice versa.
To connect a running container to an existing user-defined bridge, use the docker network connect command. The
following command connects an already-running my-nginx container to an already-existing my-net network:
[Link] 8/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
Yes, Docker support IPv6. IPv6 networking is only supported on Docker daemons running on Linux [Link] for
IPv6 address has been there since Docker Engine 1.5 [Link] enable IPv6 support in the Docker daemon, you
need to edit /etc/docker/[Link] and set the ipv6 key to true.
{
"ipv6": true
}
You can now create networks with the --ipv6 flag and assign containers IPv6 addresses using the --ip6 flag.
[Link] 9/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
Bridge networks connect two networks while creating a single aggregate network from multiple communication
networks or network segments, hence the name bridge. Overlay networks are usually used to create a virtual
network between two separate hosts. Virtual, since the network is build over an existing network. Bridge networks
can cater to single host, while overlay networks are for multiple hosts.
26. What networks are affected when you join a Docker host to an existing Swarm? When you initialize a swarm or
join a Docker host to an existing swarm, two new networks are created on that Docker host:
an overlay network called ingress, which handles control and data traffic related to swarm services. When you
create a swarm service and do not connect it to a user-defined overlay network, it connects to the ingress
network by default.
a bridge network called docker_gwbridge, which connects the individual Docker daemon to the other daemons
participating in the swarm.
[Link] 10/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
If
you want to completely disable the networking stack on a container, you can use the --network none flag when
starting the container. Within the container, only the loopback device is created. The following example illustrates
this.
[Link] 11/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
Not at all! Any data that your application writes to disk gets preserved in its container until you explicitly delete the
container. The file system for the container persists even after the container halts.
1. Launch a new container and mount the volume from the dbstore container
[Link] 12/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
3. Pass a command that tars the contents of the dbdata volume to a [Link] file inside our
/backup directory.
$ docker run --rm --volumes-from dbstore -v $(pwd):/backup ubuntu tar cvf /backup/[Link] /dbdata Restore
container from backup With the backup just created, you can restore it to the same container, or another that you
made elsewhere. For example, create a new container named dbstore2: $ docker run -v /dbdata --name dbstore2
ubuntu /bin/bash
Then un-tar the backup file in the new container`s data volume:
$ docker run --rm --volumes-from dbstore2 -v $(pwd):/backup ubuntu bash -c "cd /dbdata && tar xvf
/backup/[Link] --strip 1
[Link] 13/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
The docker-compose run command is for running “one-off” or “adhoc” tasks. It requires the service name you want
to run and only starts containers for services that the running service depends on. Use run to run tests or perform
an administrative task such as removing or adding data to a data volume container. The run command acts like
docker run -ti in that it opens an interactive terminal to the container and returns an exit status matching the exit
status of the process in the container. The docker-compose start command is useful only to restart containers that
were previously created, but were stopped. It never creates new containers.
When you run docker-compose up, the web service defined above uses the image alpine:v3.4. You can verify this
with the docker-compose config command which prints your resolved application config to the terminal:
[Link] 14/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
You can also specify this within a docker run command, such as:
Please note that EXPOSE will not allow communication via the defined ports to containers outside of the same
network or to the host machine. To allow this to happen you need to publish the ports.
If you try building this Docker image using docker build command -
[Link] 15/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
This clearly state that ENTRYPOINT is meant to provide the executable while CMD is to pass the default arguments
to the executable.
If the objects on the file system that Docker is about to produce are unchanged between builds, reusing a cache of
a previous build on the host is a great time-saver. It makes building a new container really, really fast. None of those
file structures have to be created and written to disk this time — the reference to them is sufficient to locate and
reuse the previously built structures.
Underlying is the architecture laid out by the Microsoft for the Windows and Hyper-V Containers
[Link] 17/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
Applications are deployed in the form of services (or “microservices”) in a Swarm cluster. Docker Compose is a tool
which is majorly used to deploy the app. Applications are deployed in the form of a combination of pods,
deployments, and services (or “microservices”). Autoscaling feature is not available either in Docker Swarm
(Classical) or Docker Swarm Auto-scaling feature is available under K8s. It uses a simple number-of-pods target
which is defined declaratively using deployments. CPU-utilization-per-pod target is available.
Docker Swarm support rolling updates features. At rollout time, you can apply rolling updates to services. The
Swarm manager lets you control the delay between service deployment to different sets of nodes, thereby updating
only 1 task at a time. Under kubernetes, the deployment controller supports both “rolling-update” and “recreate”
strategies. Rolling updates can specify maximum number of pods unavailable or maximum number running during
the process. Under Docker Swarm Mode, the node joining a Docker Swarm cluster creates an overlay network for
services that span all of the hosts in the Swarm and a host only Docker bridge network for containers. By default,
nodes in the Swarm cluster encrypt overlay control and management traffic between themselves. Users can choose
to encrypt container data traffic when creating an overlay network by themselves. Under K8s, the networking model
is a flat network, enabling all pods to communicate with one another. Network policies specify how pods
communicate with each other. The flat network is typically implemented as an overlay.
Docker Swarm health checks are limited to services. If a container backing the service does not come up (running
state), a new container is kicked off. Users can embed health check functionality into their Docker images using the
HEALTHCHECK instruction. Under K8s, the health checks are of two kinds: liveness (is app responsive) and readiness
(is app responsive, but busy preparing and not yet able to serve) Out-of-the-box K8S provides a basic logging
mechanism to pull aggregate logs for a set of containers that make up a pod.
[Link] 18/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
HA refers to High Availability. High Availability is a feature where you have multiple instances of your applications
running in parallel to handle increased load or failures. These two paradigms fit perfectly into Docker Swarm, the
built-in orchestrator that comes with Docker. Deploying your applications like this will improve your uptime which
translates to happy users. For creating a high availability container in the Docker Swarm, we need to deploy a
docker service to the swarm with nginx image. This can be done by using docker swarm create command as
specified above.
[Link] 20/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
Routing Mesh is a feature which make use of Load Balancer [Link] provides global publish port for a given
service. The routing mesh uses port based service discovery and load balancing. So to reach any service from
outside the cluster you need to expose ports and reach them via the Published Port. Docker Engine swarm mode
makes it easy to publish ports for services to make them available to resources outside the swarm. All nodes
participate in an ingress routing mesh. The routing mesh enables each node in the swarm to accept connections on
published ports for any service running in the swarm, even if there’s no task running on the node. The routing mesh
routes all incoming requests to published ports on available nodes to an active container.
[Link] 21/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
Starting Docker CE 17.06 release, Docker provides support for local scope networks in Swarm. This includes any
local scope network driver. Some examples of these are bridge, host, and macvlan though any local scope network
driver, built-in or plug-in, will work with Swarm. Previously only swarm scope networks like overlay were supported.
MACVLAN offers a number of unique features and capabilities. It has positive performance implications by virtue of
having a very simple and lightweight architecture. It’s use cases includes very low latency applications and
networking design that requires containers be on the same subnet as and using IPs as the external host
[Link] macvlan driver uses the concept of a parent interface. This interface can be a physical interface such as
eth0, a sub-interface for 802.1q VLAN tagging like eth0.10 (.10 representing VLAN 10), or even a bonded host
adaptor which bundles two Ethernet interfaces into a single logical interface.
[Link] 22/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
In Docker there are three key components to container security and together they result in inherently safer apps.
Docker Secrets, a container native solution that strengthens the Trusted Delivery component of container security
by integrating secret distribution directly into the container platform. By integrating secrets into Docker
orchestration, we are able to deliver a solution for the secrets management problem that follows these exact
principles. The following diagram provides a high-level view of how the Docker swarm mode architecture is applied
to securely deliver a new type of object to our containers: a secret object.
[Link] 23/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
There is no need to provision or maintain any servers. There is no software or runtime to install, maintain, or
administer
FLEXIBLE SCALING
Your application can be scaled automatically or by adjusting its capacity through toggling the units of consumption
(e.g. throughput, memory) rather than units of individual servers.
Pay for consistent throughput or execution duration rather than by server unit.
Serverless provides built-in availability and fault tolerance. You don't need to architect for these capabilities since
the services running the application provide them by default.
COMPUTE
AWS Lambda
AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you
consume - there is no charge when your code is not running.
AWS Fargate
AWS Fargate is a purpose-built serverless compute engine for containers. Fargate scales and manages the
infrastructure required to run your containers.
STORAGE
Amazon Simple Storage Service (Amazon S3) provides developers and IT teams with secure, durable, highly-scalable
object storage. Amazon S3 is easy to use, with a simple web service interface to store and retrieve any amount of
data from anywhere on the web.
[Link] 24/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
DATA STORES
Amazon DynamoDB is a fast and flexible NoSQL database service for all applications that need consistent, single-
digit millisecond latency at any scale.
API PROXY
Amazon API Gateway is a fully managed service that makes it easy for developers to create, publish, maintain,
monitor, and secure APIs at any scale. It offers a comprehensive platform for API management. API Gateway allows
you to process hundreds of thousands of concurrent API calls and handles traffic management, authorization and
access control, monitoring, and API version management.
APPLICATION INTEGRATION
Amazon SNS is a fully managed pub/sub messaging service that makes it easy to decouple and scale microservices,
distributed systems, and serverless applications.
ORCHESTRATION
AWS Step Functions makes it easy to coordinate the components of distributed applications and microservices
using visual workflows. Building applications from individual components that each perform a discrete function lets
you scale and change applications quickly. Step Functions is a reliable way to coordinate components and step
through the functions of your application.
ANALYTICS
Amazon Kinesis is a platform for streaming data on AWS, offering powerful services to make it easy to load and
analyze streaming data, and also providing the ability for you to build custom streaming data applications for
specialized needs.
DEVELOPER TOOLING
AWS provides tools and services that aid developers in the serverless application development process. AWS and its
partner ecosystem offer tools for continuous integration and delivery, testing, deployments, monitoring and
diagnostics, SDKs, frameworks, and integrated development environment (IDE) plugins.
[Link] 25/26
9/9/23, 2:28 PM dockerlabs/docker/[Link] at master · collabnix/dockerlabs · GitHub
[Link] 26/26