<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://dikapediav2.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Docker_Troubleshooting_and_CLI</id>
	<title>Docker Troubleshooting and CLI - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://dikapediav2.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Docker_Troubleshooting_and_CLI"/>
	<link rel="alternate" type="text/html" href="https://dikapediav2.com/wiki/index.php?title=Docker_Troubleshooting_and_CLI&amp;action=history"/>
	<updated>2026-05-15T09:21:16Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://dikapediav2.com/wiki/index.php?title=Docker_Troubleshooting_and_CLI&amp;diff=59&amp;oldid=prev</id>
		<title>Ardika Sulistija: Created page with &quot;* &lt;b&gt;Docker&lt;/b&gt; (Main page) * &lt;b&gt;ECR&lt;/b&gt;    ----   ====&lt;u&gt;Common Docker CLI commands and troubleshooting concepts&lt;/u&gt;====  * The &lt;b&gt;$ docker pull&lt;/b&gt; command allows you to download an image or set of images (i.e. repository). * The &lt;b&gt;$ docker images&lt;/b&gt; command allows you to list the currently downloaded images.  * The &lt;b&gt;$ docker build&lt;/b&gt; command builds an image from a Dockerfile and a context. The build&#039;s context is processed...&quot;</title>
		<link rel="alternate" type="text/html" href="https://dikapediav2.com/wiki/index.php?title=Docker_Troubleshooting_and_CLI&amp;diff=59&amp;oldid=prev"/>
		<updated>2024-08-21T14:48:56Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;* &lt;a href=&quot;/wiki/Docker&quot; title=&quot;Docker&quot;&gt;&amp;lt;b&amp;gt;Docker&amp;lt;/b&amp;gt;&lt;/a&gt; (Main page) * &lt;a href=&quot;/wiki/ECR&quot; title=&quot;ECR&quot;&gt;&amp;lt;b&amp;gt;ECR&amp;lt;/b&amp;gt;&lt;/a&gt;    ----   ====&amp;lt;u&amp;gt;Common Docker CLI commands and troubleshooting concepts&amp;lt;/u&amp;gt;====  * The &amp;lt;b&amp;gt;$ docker pull&amp;lt;/b&amp;gt; command allows you to download an image or set of images (i.e. repository). * The &amp;lt;b&amp;gt;$ docker images&amp;lt;/b&amp;gt; command allows you to list the currently downloaded images.  * The &lt;a href=&quot;#Building_an_Image&quot;&gt;&amp;lt;b&amp;gt;$ docker build&amp;lt;/b&amp;gt;&lt;/a&gt; command builds an image from a Dockerfile and a context. The build&amp;#039;s context is processed...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;* [[Docker|&amp;lt;b&amp;gt;Docker&amp;lt;/b&amp;gt;]] (Main page)&lt;br /&gt;
* [[ECR|&amp;lt;b&amp;gt;ECR&amp;lt;/b&amp;gt;]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;Common Docker CLI commands and troubleshooting concepts&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;b&amp;gt;$ docker pull&amp;lt;/b&amp;gt; command allows you to download an image or set of images (i.e. repository).&lt;br /&gt;
* The &amp;lt;b&amp;gt;$ docker images&amp;lt;/b&amp;gt; command allows you to list the currently downloaded images. &lt;br /&gt;
* The [[#Building an Image|&amp;lt;b&amp;gt;$ docker build&amp;lt;/b&amp;gt;]] command builds an image from a Dockerfile and a context. The build&amp;#039;s context is processed recursively and refers to the set of files in the specified location PATH or URL.&lt;br /&gt;
* The [[#Pushing an Image|&amp;lt;b&amp;gt;$ docker push&amp;lt;/b&amp;gt;]] command allows you to push an Image or repository to a registry.&lt;br /&gt;
* The [[#How to Remove Docker Images|&amp;lt;b&amp;gt;$ docker rmi&amp;lt;/b&amp;gt;]] command allows you to delete an image.&lt;br /&gt;
* The &amp;lt;b&amp;gt;$ docker ps&amp;lt;/b&amp;gt; command allows you to list the currently running docker processes.&lt;br /&gt;
* The [[#How to run a docker container|&amp;lt;b&amp;gt;$ docker run&amp;lt;/b&amp;gt;]] command allows you to start a new container. Often, this will be done in the &amp;quot;detached&amp;quot; (-d) mode to run the process in the background.&lt;br /&gt;
* The &amp;lt;b&amp;gt;$ docker stop&amp;lt;/b&amp;gt; command allows you to stop a currently running container.&lt;br /&gt;
* The [[#How to remove a docker container|&amp;lt;b&amp;gt;$ docker rm&amp;lt;/b&amp;gt;]] command allows you to remove one or more containers.&lt;br /&gt;
* The [[#To run a command inside of a running container|&amp;lt;b&amp;gt;$ docker exec&amp;lt;/b&amp;gt;]] command allows you to run a command inside a running container. This is useful for troubleshooting the container.&lt;br /&gt;
* The &amp;lt;b&amp;gt;$ docker logs&amp;lt;/b&amp;gt; command allows you to view the log output (stdout and stderr) of a container.&lt;br /&gt;
* The [[#To find detailed information on Constructs controlled by Docker|&amp;lt;b&amp;gt;$ docker inspect&amp;lt;/b&amp;gt;]] command allows you to get details about any Docker object. It is most commonly used to inspect a container to get information like the environment variables, network configuration, etc. &lt;br /&gt;
* The [[#Docker info|&amp;lt;b&amp;gt;$ docker info&amp;lt;/b&amp;gt;]] command allows you to get details about the currently running Docker Daemon.&lt;br /&gt;
* The [[#How to manage containers in namespaces by using nsenter|&amp;lt;b&amp;gt;$ nsenter&amp;lt;/b&amp;gt;]] command executes program in different namespaces.&lt;br /&gt;
* The [[#How to view the namespaces associated to a container|&amp;lt;b&amp;gt; $ lsns&amp;lt;/b&amp;gt;]] command lists namespaces. It lists information about all the currently accessible namespaces or about the given namespace. &lt;br /&gt;
* The [[#How to create docker volume|&amp;lt;b&amp;gt;$ docker volume&amp;lt;/b&amp;gt;]] command to create a docker volume or list volumes. &lt;br /&gt;
* [[#Netshoot|&amp;lt;b&amp;gt;Netshoot&amp;lt;/b&amp;gt;]] is a container image that allows you to launch in the same network namespace of a running container, so you can troubleshoot using tools in the Netshoot container. This helps prevent you from installing tools on your running container in order to keep it light.  ([https://github.com/nicolaka/netshoot &amp;lt;b&amp;gt;Github link&amp;lt;/b&amp;gt;])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;How to start the Docker Daemon&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
If you don’t want to use a system utility to manage the Docker daemon, or just want to test things out, you can manually run it using the &amp;lt;b&amp;gt;$ dockerd&amp;lt;/b&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
When you start Docker this way, it runs in the foreground and sends its logs directly to your terminal.&lt;br /&gt;
 $ dockerd &lt;br /&gt;
 &lt;br /&gt;
 INFO[0000] +job init_networkdriver()&lt;br /&gt;
 INFO[0000] +job serveapi(unix:///var/run/docker.sock)&lt;br /&gt;
 INFO[0000] Listening for HTTP on unix (/var/run/docker.sock)&lt;br /&gt;
&lt;br /&gt;
To stop Docker when you have started it manually, issue a Ctrl+C in your terminal.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;Container exits unexpectedly&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
* Memory exhaustion (OOM error)&lt;br /&gt;
** Possible resolutions:&lt;br /&gt;
*** Setting hard memory ceiling by increasing the memory value in your &amp;lt;b&amp;gt;$ docker run&amp;lt;/b&amp;gt; comman using the &amp;lt;b&amp;gt;-m&amp;lt;/b&amp;gt; option, and&lt;br /&gt;
*** Setting a soft-limit for memory usage, which is activated when the Docker daemon detects contention or low host memory. This can be set during &amp;lt;b&amp;gt;$ docker run&amp;lt;/b&amp;gt; using the &amp;lt;b&amp;gt;--memory-reservation&amp;lt;/b&amp;gt; option, which must have a value lower than the value set with the &amp;lt;b&amp;gt;-m&amp;lt;/b&amp;gt; option.&lt;br /&gt;
* Application failure&lt;br /&gt;
* Out of Disk space&lt;br /&gt;
** Possible causes:&lt;br /&gt;
*** Containers that have been stopped for an extended period of time.&lt;br /&gt;
*** Images that belong to containers that are no longer active on the host.&lt;br /&gt;
** To clean up disk space:&lt;br /&gt;
 $ docker system prune -a&lt;br /&gt;
&lt;br /&gt;
Things to check when &amp;lt;b&amp;gt;Container exits unexpectedly&amp;lt;/b&amp;gt;:&lt;br /&gt;
 $ docker ps -a&lt;br /&gt;
** This command can be used to check the container exit code.&lt;br /&gt;
** An exit code is the code returned to a parent process by an executable. Where 0 is the exit code for success and any non-zero indicates a failure of some kind. &lt;br /&gt;
 &lt;br /&gt;
 $ docker logs -t &amp;lt;containerID&amp;gt;&lt;br /&gt;
* This command can help provide visibility into the events of the application running inside the container if the logging driver being used is json file. (which is the default logging driver for Docker on Linux).&lt;br /&gt;
&lt;br /&gt;
 $ docker info | grep -i &amp;quot;data space&amp;quot;&lt;br /&gt;
* THis command is very useful when needing to determine available disk space on a system configured wth an LVM partition (devicemapper as Docekr storage driver).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;Cannot connect to application&amp;lt;/u&amp;gt;====&lt;br /&gt;
* Application not listening on configured port&lt;br /&gt;
* Host and/or container port misconfigured&lt;br /&gt;
* Firewall/Antivirus on host machine&lt;br /&gt;
&lt;br /&gt;
Things to check when &amp;lt;b&amp;gt;cannot connect to application&amp;lt;/b&amp;gt;:&lt;br /&gt;
 $ docker ps -a&lt;br /&gt;
* Check the port configurations for the container when you can&amp;#039;t reach the service inside a running container.&lt;br /&gt;
&lt;br /&gt;
 $ docker logs --tail &amp;lt;containerid&amp;gt;&lt;br /&gt;
* To view stdout and stderr output from the application running in a container.&lt;br /&gt;
&lt;br /&gt;
 $ docker exec -it &amp;lt;containerid&amp;gt; bash/&amp;lt;command&amp;gt;&lt;br /&gt;
* If the container is running, you can start a shell session by using the above command to troubleshoot application inside running container. &lt;br /&gt;
* This provides access to view logs not exported to the host instance.&lt;br /&gt;
* Please note a shell session might or might not be available depending upon the image being used. &lt;br /&gt;
&lt;br /&gt;
 $ docker inspect &amp;lt;containerid&amp;gt; --format &amp;#039;{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}&amp;#039;&lt;br /&gt;
* This comman provides detailed information in a json format for the specified container ID. The &amp;lt;b&amp;gt;format&amp;lt;/b&amp;gt; option can be used to get specific inofmration from the json body.&lt;br /&gt;
&lt;br /&gt;
 $ curl -I &amp;lt;containerIP&amp;gt;:&amp;lt;containerPort&amp;gt; &lt;br /&gt;
* If the port mapping is correct and you have shell access on the container host, this comman will return the HTTP status code returned by your application, if it is running.&lt;br /&gt;
&lt;br /&gt;
 $ netstat -nota&lt;br /&gt;
* Use this command to check if the host port is listening on the container instance.&lt;br /&gt;
&lt;br /&gt;
For a misconfigured Host/Container port:&lt;br /&gt;
* If the host and/or container ports are misconfigured, stop the currently running container then start a new container using the same image, but with the correct port mapping. &lt;br /&gt;
&lt;br /&gt;
For applications not listening on port specfied by Docker run, either:&lt;br /&gt;
* Modify the container application&amp;#039;s configuration to listen on the desired port.&lt;br /&gt;
* Correct Dockerfile expose port and rebuild/push the Docker image.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;Check if Docker is running&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
 $ ps aux | grep -i docker&lt;br /&gt;
 $ docker info&lt;br /&gt;
 $ sudo systemctl status docker&lt;br /&gt;
 $ sudo systemctl is-active docker&lt;br /&gt;
 $ sudo service docker status&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;Docker info&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
 $ docker info&lt;br /&gt;
 Client:&lt;br /&gt;
  Debug Mode: false&lt;br /&gt;
 &lt;br /&gt;
 Server:&lt;br /&gt;
  Containers: 3&lt;br /&gt;
   Running: 0&lt;br /&gt;
   Paused: 0&lt;br /&gt;
   Stopped: 3&lt;br /&gt;
  Images: 4&lt;br /&gt;
  Server Version: 19.03.6-ce&lt;br /&gt;
  Storage Driver: overlay2&lt;br /&gt;
   Backing Filesystem: extfs&lt;br /&gt;
   Supports d_type: true&lt;br /&gt;
   Native Overlay Diff: true&lt;br /&gt;
  Logging Driver: json-file&lt;br /&gt;
  Cgroup Driver: cgroupfs&lt;br /&gt;
  Plugins:&lt;br /&gt;
   Volume: local&lt;br /&gt;
   Network: bridge host ipvlan macvlan null overlay&lt;br /&gt;
   Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog&lt;br /&gt;
  Swarm: inactive&lt;br /&gt;
  Runtimes: runc&lt;br /&gt;
  Default Runtime: runc&lt;br /&gt;
  Init Binary: docker-init&lt;br /&gt;
  containerd version: ff48f57fc83a8c44cf4ad5d672424a98ba37ded6&lt;br /&gt;
  runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd&lt;br /&gt;
  init version: fec3683&lt;br /&gt;
  Security Options:&lt;br /&gt;
   seccomp&lt;br /&gt;
    Profile: default&lt;br /&gt;
  Kernel Version: 4.14.193-149.317.amzn2.x86_64&lt;br /&gt;
  Operating System: Amazon Linux 2&lt;br /&gt;
  OSType: linux&lt;br /&gt;
  Architecture: x86_64&lt;br /&gt;
  CPUs: 1&lt;br /&gt;
  Total Memory: 983.3MiB&lt;br /&gt;
  Name: ip-172-31-63-97.ec2.internal&lt;br /&gt;
  ID: M4YS:RHVD:QMWR:F6EY:EB7L:XA7U:ZWK4:22VI:I22D:NSN7:SYS5:IWSW&lt;br /&gt;
  Docker Root Dir: /var/lib/docker&lt;br /&gt;
  Debug Mode: false&lt;br /&gt;
  Registry: https://index.docker.io/v1/&lt;br /&gt;
  Labels:&lt;br /&gt;
  Experimental: false&lt;br /&gt;
  Insecure Registries:&lt;br /&gt;
   127.0.0.0/8&lt;br /&gt;
  Live Restore Enabled: false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;How to run a docker container&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
* If you want to keep the container and current terminal session separate, you can run the container in the background using the -d attribute. Using detached mode also allows you to close the opened terminal session without stopping the container.&lt;br /&gt;
&lt;br /&gt;
 $ docker run -d nginx:latest&lt;br /&gt;
 Unable to find image &amp;#039;nginx:latest&amp;#039; locally&lt;br /&gt;
 latest: Pulling from library/nginx&lt;br /&gt;
 bf5952930446: Pull complete &lt;br /&gt;
 cb9a6de05e5a: Pull complete &lt;br /&gt;
 9513ea0afb93: Pull complete &lt;br /&gt;
 b49ea07d2e93: Pull complete &lt;br /&gt;
 a5e4a503d449: Pull complete &lt;br /&gt;
 Digest: sha256:b0ad43f7ee5edbc0effbc14645ae7055e21bc1973aee5150745632a24a752661&lt;br /&gt;
 Status: Downloaded newer image for nginx:latest&lt;br /&gt;
 80984b890f33b27fd2fab0cfc307cd8ed8096e15e86d75522ef27ca719550e80&lt;br /&gt;
&lt;br /&gt;
To run a docker container and have the mapping port 8080 of the HOST ENI to port 80 of the docker container:&lt;br /&gt;
 $ docker run -d -p 8080:80 nginx:latest&lt;br /&gt;
 e892531ea4a62495dd86f3e874e3eea242df7d983faabf6957b6b0fa8e4ef256&lt;br /&gt;
 &lt;br /&gt;
 $ docker ps&lt;br /&gt;
 CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES&lt;br /&gt;
 e892531ea4a6        nginx:latest        &amp;quot;/docker-entrypoint.…&amp;quot;   3 minutes ago       Up 3 minutes        0.0.0.0:8080-&amp;gt;80/tcp   sharp_panini&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;Check Docker Images&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
 $ docker images&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;List all containers&amp;lt;/u&amp;gt;====&lt;br /&gt;
 &lt;br /&gt;
By default only shows &amp;#039;running&amp;#039; containers&lt;br /&gt;
 $ docker ps &lt;br /&gt;
&lt;br /&gt;
--all containers including stopped ones&lt;br /&gt;
 $ docker ps -a&lt;br /&gt;
&lt;br /&gt;
--quiet; only IDs&lt;br /&gt;
 $ docker ps -aq&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;Stop a container&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
 $ docker stop my_container&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;Stop all running containers/images&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
Stop all running containers&lt;br /&gt;
 $ docker stop $(docker ps -aq)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;How to remove a docker container&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
Remove a container&lt;br /&gt;
 $ docker rm &amp;lt;container ID&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove all containers&lt;br /&gt;
 $ docker rm $(docker ps -aq)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;To run a command inside of a running container&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
 $ docker exec&lt;br /&gt;
&lt;br /&gt;
* This comman comes in handy if you need to connect to the container to troubleshoot the application within.&lt;br /&gt;
&lt;br /&gt;
 $ docker exec -it &amp;lt;containerid&amp;gt; bash&lt;br /&gt;
 $ docker exec -ti 96cc52ffd1b0 mount&lt;br /&gt;
* If the container is running, you can start a bash shell session by using the above command to troubleshoot application inside running container. &lt;br /&gt;
* This provides access to view logs not exported to the host instance.&lt;br /&gt;
* Please note a shell session might or might not be available depending upon the image being used. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;To find detailed information on Constructs controlled by Docker&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
This command is especially useful to find the container&amp;#039;s IP address, the container status, exit code, and errors to name a few.&lt;br /&gt;
&lt;br /&gt;
You can also use this command to view additional details of an image, such as its size and layers.&lt;br /&gt;
 $ docker inspect&lt;br /&gt;
&lt;br /&gt;
To get an instances IP address:&lt;br /&gt;
 $ docker inspect &amp;lt;containerid&amp;gt; --format &amp;#039;{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Inspect details of a docker image:&lt;br /&gt;
 $ docker inspect image_id&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt; How to find the PID of a docker container (Two ways)&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
Simpler way: &amp;lt;b&amp;gt;$ docker top &amp;lt;container ID&amp;lt;/b&amp;gt;:&lt;br /&gt;
 $ docker top 80a282dff43f&lt;br /&gt;
 UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD&lt;br /&gt;
 root                11944               11909               0                   21:40               ?                   00:00:00            nginx: master process nginx -g daemon off;&lt;br /&gt;
 101                 12003               11944               0                   21:40               ?                   00:00:00            nginx: worker process&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To find the PID of a docker container, run &amp;lt;b&amp;gt;$ docker ps&amp;lt;/b&amp;gt; to get the container ID:&lt;br /&gt;
 [ec2-user@ip-172-31-63-97 proc]$ docker ps&lt;br /&gt;
 CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES&lt;br /&gt;
 80a282dff43f        nginx:latest        &amp;quot;/docker-entrypoint.…&amp;quot;   21 minutes ago      Up 21 minutes       80/tcp              demo&lt;br /&gt;
&lt;br /&gt;
Then run &amp;lt;u&amp;gt;$ docker inspect --format &amp;#039; { { .State.Pid } } &amp;#039; &amp;lt;container ID&amp;gt;&amp;lt;/u&amp;gt;:&lt;br /&gt;
 [ec2-user@ip-172-31-63-97 proc]$ docker inspect --format &amp;#039;{{.State.Pid}}&amp;#039; 80a282dff43f&lt;br /&gt;
 11944&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;How to manage containers in namespaces by using nsenter&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
How to view the &amp;lt;b&amp;gt;network&amp;lt;/b&amp;gt; namespace of the Docker container using &amp;lt;b&amp;gt;$ nsenter -t &amp;lt;container PID&amp;gt; -n &amp;lt;command&amp;gt;&amp;lt;/b&amp;gt;:&lt;br /&gt;
* &amp;lt;b&amp;gt;n&amp;lt;/b&amp;gt; = Network namespace&lt;br /&gt;
 $ sudo nsenter -t 11944 -n bash&lt;br /&gt;
 &lt;br /&gt;
 [root@ip-172-31-63-97 ec2-user]# ifconfig&lt;br /&gt;
 eth0: flags=4163&amp;lt;UP,BROADCAST,RUNNING,MULTICAST&amp;gt;  mtu 1500&lt;br /&gt;
         inet 172.17.0.2  netmask 255.255.0.0  broadcast 172.17.255.255&lt;br /&gt;
         ether 02:42:ac:11:00:02  txqueuelen 0  (Ethernet)&lt;br /&gt;
         RX packets 20  bytes 1592 (1.5 KiB)&lt;br /&gt;
         RX errors 0  dropped 0  overruns 0  frame 0&lt;br /&gt;
         TX packets 0  bytes 0 (0.0 B)&lt;br /&gt;
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0&lt;br /&gt;
 &lt;br /&gt;
 lo: flags=73&amp;lt;UP,LOOPBACK,RUNNING&amp;gt;  mtu 65536&lt;br /&gt;
         inet 127.0.0.1  netmask 255.0.0.0&lt;br /&gt;
         loop  txqueuelen 1000  (Local Loopback)&lt;br /&gt;
         RX packets 0  bytes 0 (0.0 B)&lt;br /&gt;
         RX errors 0  dropped 0  overruns 0  frame 0&lt;br /&gt;
         TX packets 0  bytes 0 (0.0 B)&lt;br /&gt;
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0&lt;br /&gt;
&lt;br /&gt;
OR you can simply do this: &amp;lt;b&amp;gt;$ sudo nsenter -t 11944 -n ifconfig&amp;lt;/b&amp;gt;, &lt;br /&gt;
 # sudo nsenter -t 11944 -n ifconfig&lt;br /&gt;
 eth0: flags=4163&amp;lt;UP,BROADCAST,RUNNING,MULTICAST&amp;gt;  mtu 1500&lt;br /&gt;
         inet 172.17.0.2  netmask 255.255.0.0  broadcast 172.17.255.255&lt;br /&gt;
         ether 02:42:ac:11:00:02  txqueuelen 0  (Ethernet)&lt;br /&gt;
         RX packets 20  bytes 1592 (1.5 KiB)&lt;br /&gt;
         RX errors 0  dropped 0  overruns 0  frame 0&lt;br /&gt;
         TX packets 0  bytes 0 (0.0 B)&lt;br /&gt;
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0&lt;br /&gt;
&lt;br /&gt;
* You are now viewing the network configuration as perceived from INSIDE the running container. This is the internal IP on the other side of the network bridge. &lt;br /&gt;
* You can now run network tools without having to run the actual commands from within the container. In other words, you dont have to load up and install the container with troubleshooting tools in order to troubleshoot since you always want the container to be as light as possible. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;How to view the namespaces associated to a container&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
You can use &amp;lt;b&amp;gt;$ lsns -p &amp;lt;container pid&amp;gt;&amp;lt;/b&amp;gt; command, which lists the namespaces.&lt;br /&gt;
* Note, you can see these namespaces in the &amp;lt;b&amp;gt;/proc/&amp;lt;container pid&amp;gt;&amp;lt;/b&amp;gt; directory as well.&lt;br /&gt;
 # lsns -p 11944&lt;br /&gt;
         NS TYPE   NPROCS   PID USER COMMAND&lt;br /&gt;
 4026531835 cgroup    104     1 root /usr/lib/systemd/systemd --switched-root --system --deserialize 21&lt;br /&gt;
 4026531837 user      104     1 root /usr/lib/systemd/systemd --switched-root --system --deserialize 21&lt;br /&gt;
 4026532220 mnt         2 11944 root nginx: master process nginx -g daemon off&lt;br /&gt;
 4026532221 uts         2 11944 root nginx: master process nginx -g daemon off&lt;br /&gt;
 4026532222 ipc         2 11944 root nginx: master process nginx -g daemon off&lt;br /&gt;
 4026532223 pid         2 11944 root nginx: master process nginx -g daemon off&lt;br /&gt;
 4026532225 net         3 11944 root nginx: master process nginx -g daemon off&lt;br /&gt;
 &lt;br /&gt;
 # ls /proc/11944/ns&lt;br /&gt;
 cgroup  ipc  mnt  net  pid  pid_for_children  user  uts&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;Building an Image&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Prerequisites&amp;lt;/b&amp;gt;:&lt;br /&gt;
First create an index.html file, then create Dockerfile:&lt;br /&gt;
 $ cat index.html &lt;br /&gt;
 hello&lt;br /&gt;
 &lt;br /&gt;
 $ cat &amp;lt;&amp;lt;EOF&amp;gt; Dockerfile&lt;br /&gt;
 &amp;gt; FROM nginx&lt;br /&gt;
 &amp;gt; COPY index.html /usr/share/nginx/html/index.html&lt;br /&gt;
 &amp;gt; EXPOSE 80&lt;br /&gt;
 &amp;gt; EOF&lt;br /&gt;
&lt;br /&gt;
 $ cat Dockerfile&lt;br /&gt;
 FROM nginx&lt;br /&gt;
 COPY index.html /usr/share/nginx/html/index.html&lt;br /&gt;
 EXPOSE 80&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tell Docker daemon to use the current directory as context:&lt;br /&gt;
 $ docker build&lt;br /&gt;
&lt;br /&gt;
Tell Docker daemon to create an image called &amp;quot;my_image&amp;quot; while using the current directory as the context.&lt;br /&gt;
 $ docker build -t my_image .&lt;br /&gt;
 Sending build context to Docker daemon  10.75kB&lt;br /&gt;
 Step 1/3 : FROM nginx&lt;br /&gt;
  ---&amp;gt; 4bb46517cac3&lt;br /&gt;
 Step 2/3 : COPY index.html /usr/share/nginx/html/index.html&lt;br /&gt;
  ---&amp;gt; d642224125aa&lt;br /&gt;
 Step 3/3 : EXPOSE 80&lt;br /&gt;
  ---&amp;gt; Running in 13ce51f632e1&lt;br /&gt;
 Removing intermediate container 13ce51f632e1&lt;br /&gt;
  ---&amp;gt; b10d01f10725&lt;br /&gt;
 Successfully built b10d01f10725&lt;br /&gt;
 Successfully tagged my_image:latest&lt;br /&gt;
&lt;br /&gt;
* Now your image is created and you can see it in Docker:&lt;br /&gt;
 $ docker images&lt;br /&gt;
 REPOSITORY                TAG                 IMAGE ID            CREATED              SIZE&lt;br /&gt;
 my_image                  latest              b10d01f10725        About a minute ago   133MB&lt;br /&gt;
&lt;br /&gt;
Tell Docker daemoin to create an image called &amp;quot;my_image&amp;quot; while using the context from the path specified to find the necessary [[#Dockerfile|&amp;lt;b&amp;gt;Dockerfile&amp;lt;/b&amp;gt;]].&lt;br /&gt;
 $ docker build -t my_image -f /path/to/dockerfile&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;Pushing an Image&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
You can use the &amp;lt;b&amp;gt;$ docker push&amp;lt;/b&amp;gt; command to push an Image or repository to a registry. You can share images to Docker Hub registry, ECR, or to a self-hosted one. &lt;br /&gt;
&lt;br /&gt;
Progress bars shown when running &amp;lt;b&amp;gt;$ docker push&amp;lt;/b&amp;gt; show the uncompressed size. The actual amount of data that&amp;#039;s pushed will be compressed before sending, so the uploaded size will not be reflected by the progress bar. &lt;br /&gt;
&lt;br /&gt;
Registry credentials are managed by the &amp;lt;b&amp;gt;$ docker login&amp;lt;/b&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
 $ docker tag docker_image:latest ardika0011/dockerimage:latest&lt;br /&gt;
  &lt;br /&gt;
 $ docker push ardika0011/dockerimage:latest&lt;br /&gt;
 The push refers to repository [docker.io/ardika0011/dockerimage]&lt;br /&gt;
 1h2k3mn4n5b6: Pushed&lt;br /&gt;
 mf83jfdh2o4j: Pushed&lt;br /&gt;
 734hjkgdsk23: Pushed&lt;br /&gt;
 lfkjwd209jfl: Pushed&lt;br /&gt;
 flk2jr3oif2j: Pushed&lt;br /&gt;
 latest: digest: sha256:007a1cebb6c292c2d54f6d39159fdkjsahflhafhekalhfdfdskafkh22h3 size: 2200&lt;br /&gt;
&lt;br /&gt;
* In this example, you can see the image is being pushed to Docker Hub. * We have created a repository in the Docker Hub registry (docker.io/ardika0011/dockerimage?)&lt;br /&gt;
* After creating the repository, we tagged the image that we built locally using the &amp;lt;b&amp;gt;$ docker tag&amp;lt;/b&amp;gt; command, to refer to the Docker Hub repository.&lt;br /&gt;
* Upon completion of tagging, we then pushed the image to the repository using the &amp;lt;b&amp;gt;$ docker push&amp;lt;/b&amp;gt; command. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====How to create an image of running container and Push Image to [[ECR|&amp;lt;b&amp;gt;ECR&amp;lt;/b&amp;gt;]]====&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
This instructions is to create image of an existing container, and push that image to ECR. If you have a repository created already, follow the steps to Push an Image to ECR.&lt;br /&gt;
&lt;br /&gt;
* This utilizes &amp;quot;&amp;lt;b&amp;gt;docker commit&amp;lt;/b&amp;gt;&amp;quot; command, and not the &amp;quot;&amp;lt;b&amp;gt;docker build&amp;lt;/b&amp;gt;&amp;quot; command. &lt;br /&gt;
** There will be differences in size. &amp;lt;b&amp;gt;Docker commit&amp;lt;/b&amp;gt; is basically taking a &amp;quot;snapshot&amp;quot; of the current state of the &amp;quot;running&amp;quot; container and save it as an image. ... On the other hand, &amp;lt;b&amp;gt;docker build&amp;lt;/b&amp;gt; create the image by referring to a script (Dockerfile). &lt;br /&gt;
** Learn more about the differences: https://stackoverflow.com/questions/26110828/should-i-use-dockerfiles-or-image-commits&lt;br /&gt;
&lt;br /&gt;
1) List docker containers and identify the container ID:&lt;br /&gt;
 $ docker ps -a&lt;br /&gt;
&lt;br /&gt;
2) To create a new image from a container’s changes:&lt;br /&gt;
 $ docker commit &amp;lt;container-id&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) List docker images and identify the image ID:&lt;br /&gt;
 $ docker images&lt;br /&gt;
&lt;br /&gt;
4) Create a tag for the target image to refer to the source image id:&lt;br /&gt;
 $ docker tag &amp;lt;source-image-id&amp;gt; &amp;lt;aws_account_id&amp;gt;.dkr.ecr.region.amazonaws.com/&amp;lt;repository-name&amp;gt;:&amp;lt;tag&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 #Example: &lt;br /&gt;
 $ docker tag c4257e433c9e 648818476623.dkr.ecr.us-east-1.amazonaws.com/myimagehello:test&lt;br /&gt;
&lt;br /&gt;
5) From here you simply have to follow the rest of the ECR push commands. To push the image to ECR. &lt;br /&gt;
 $ aws ecr get-login-password | docker login --username AWS --password-stdin &amp;lt;aws_account_id&amp;gt;.dkr.ecr.&amp;lt;region&amp;gt;.amazonaws.com&lt;br /&gt;
 &lt;br /&gt;
 #Example: &lt;br /&gt;
 $ aws ecr get-login-password | docker login --username AWS --password-stdin 648818476623.dkr.ecr.us-east-1.amazonaws.com&lt;br /&gt;
&lt;br /&gt;
6) Push to ECR&lt;br /&gt;
 $ docker push &amp;lt;aws_account_id&amp;gt;.dkr.ecr.&amp;lt;region&amp;gt;.amazonaws.com/&amp;lt;repository-name&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
 #Example: &lt;br /&gt;
 $ docker push 648818476623.dkr.ecr.us-east-1.amazonaws.com/myimagehello &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Click here for more details about [[ECR#How_to_create_an_image_of_running_container_and_Push_Image_to_ECR |&amp;lt;b&amp;gt;pushing an image to ECR&amp;lt;/b&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;How to Remove Docker Images&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To remove a docker image, you must first remove the docker containers which are using that image (even if they are stopped). Run:&lt;br /&gt;
* &amp;lt;b&amp;gt;$ docker rm &amp;lt;container id&amp;lt;/b&amp;gt;&lt;br /&gt;
* &amp;lt;b&amp;gt;$ docker rmi &amp;lt;image Id&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 $ docker rmi 6d7e8891c980&lt;br /&gt;
 Error response from daemon: conflict: unable to delete 6d7e8891c980 (must be forced) - image is being used by stopped container 5218f09f2897&lt;br /&gt;
 &lt;br /&gt;
 $ docker rm 5218f09f2897&lt;br /&gt;
 5218f09f2897&lt;br /&gt;
 &lt;br /&gt;
 $ docker rmi 6d7e8891c980&lt;br /&gt;
 Untagged: nicolaka/netshoot:latest&lt;br /&gt;
 Untagged: nicolaka/netshoot@sha256:04786602e5a9463f40da65aea06fe5a825425c7df53b307daa21f828cfe40bf8&lt;br /&gt;
 Deleted: sha256:6d7e8891c980fc1be88cff226843e8e08537c27879faa14452ceaa3d0300adcb&lt;br /&gt;
 Deleted: sha256:9e2a80b1e7f476596dba3bf86251fa56a48164cb476d04ee65131ab2d21ebf7b&lt;br /&gt;
 Deleted: sha256:34ea08a72d7cb2938fe9dcb7806abafa610a9fa1ba22b80c0bb3642b21531ea2&lt;br /&gt;
 Deleted: sha256:b7cf6552f05366a23e6ceb0f497cc818b2a03543a3201cbb97d168ba03f86686&lt;br /&gt;
 Deleted: sha256:427184531f9586d2e9108e3c51f67be351da0f76d2b41c82051297adcb504653&lt;br /&gt;
 Deleted: sha256:c670afd31f5a21622c21de7bc137b2ef689ef63dd0c7a48fb18b0e8bf929577e&lt;br /&gt;
 Deleted: sha256:057c21b72198a13054d683694c03ab2858e301e65faee8c50363220ddf9f3136&lt;br /&gt;
 Deleted: sha256:bb428feaff128280eecd5ed6cee6fd96f4c9011bf0b9eed93dc41234d086050a&lt;br /&gt;
 Deleted: sha256:3e207b409db364b595ba862cdc12be96dcdad8e36c59a03b7b3b61c946a5741a&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;b&amp;gt;$ docker images&amp;lt;/b&amp;gt; command with the &amp;lt;b&amp;gt;-a&amp;lt;/b&amp;gt; flag to locate the ID of the images you want to remove. This will show you every image, including intermediate image layers. When you&amp;#039;ve located the ID of the image, you can pass their ID or tag to &amp;lt;b&amp;gt;$ docker rmi&amp;lt;/b&amp;gt; command:&lt;br /&gt;
 $ docker images -a&lt;br /&gt;
 $ docker rmi Image ImageID/name&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Dangling&amp;lt;/b&amp;gt; images are layers that have no relationship to any tagged images. They no longer serve a purpose and consume disk space. They can be located by adding the filter flag, &amp;lt;b&amp;gt;-f&amp;lt;/b&amp;gt; with a valure of &amp;lt;b&amp;gt;dangling=true&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;$ docker images&amp;lt;/b&amp;gt; command. When you&amp;#039;re sure you want to delete them, use the &amp;lt;b&amp;gt;$ docker images purge&amp;lt;/b&amp;gt; command.&lt;br /&gt;
 $ docker images -f dangling=true&lt;br /&gt;
 $ docker images purge&lt;br /&gt;
&lt;br /&gt;
Remove all images&lt;br /&gt;
 $ docker rmi $(docker images -q)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;How to remove exited containers&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
You can filter the results of &amp;lt;b&amp;gt;$ docker ps&amp;lt;/b&amp;gt; command based on container status. Those status include:&lt;br /&gt;
* created&lt;br /&gt;
* restarting&lt;br /&gt;
* running&lt;br /&gt;
* paused&lt;br /&gt;
* exited.&lt;br /&gt;
&lt;br /&gt;
To review the list of exited containers use the &amp;lt;b&amp;gt;-f&amp;lt;/b&amp;gt; flag. &lt;br /&gt;
 $ docker ps -a -f status=exited&lt;br /&gt;
&lt;br /&gt;
When you&amp;#039;ve verified the containers you want to remove, use the &amp;lt;b&amp;gt;-q&amp;lt;/b&amp;gt; to pass the container IDs to the &amp;lt;b&amp;gt;$ docker rm&amp;lt;/b&amp;gt; command. &lt;br /&gt;
 $ docker rm $(docker ps -a -f status=exited -q)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;How to purge all dangling or unused Images, containers, volumes, and networks&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
Clean up dangling images: &lt;br /&gt;
 $ docker system prune&lt;br /&gt;
&lt;br /&gt;
Remove Unused Images:&lt;br /&gt;
 $ docker system prune -a&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;Check for mapped ports on the container instance to docker container&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
Another cool feature from docker is the capability to show all the mapped ports that a docker container maps to the container instance. &lt;br /&gt;
 # Obtain a container ID:&lt;br /&gt;
 $ docker ps&lt;br /&gt;
 &lt;br /&gt;
 #Take the PID #&lt;br /&gt;
 $ docker inspect -f &amp;#039;{ { .state.Pid } }&amp;#039; &amp;lt;container id&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 $ nsenter -t &amp;lt;PID&amp;gt; -n netstat -tunlp&lt;br /&gt;
 $ nsenter -t &amp;lt;PID&amp;gt; -n ifconfig -a&lt;br /&gt;
&lt;br /&gt;
* Note the netstat and ifconfig commands do not need to exist in the container&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;Netshoot&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/nicolaka/netshoot &amp;lt;b&amp;gt;Github link&amp;lt;/b&amp;gt;]&lt;br /&gt;
&lt;br /&gt;
How to run the &amp;lt;b&amp;gt;netshoot&amp;lt;/b&amp;gt; image on the same network namespace of your running container using the &amp;lt;b&amp;gt;$ docker run -it --net container:&amp;lt;container ID&amp;gt; nicolaka/netshoot&amp;lt;/b&amp;gt; command:&lt;br /&gt;
 $ docker ps&lt;br /&gt;
 CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES&lt;br /&gt;
 80a282dff43f        nginx:latest        &amp;quot;/docker-entrypoint.…&amp;quot;   About an hour ago   Up About an hour    80/tcp              demo&lt;br /&gt;
 &lt;br /&gt;
 $ docker run -it --net container:80a282dff43f nicolaka/netshoot&lt;br /&gt;
 Unable to find image &amp;#039;nicolaka/netshoot:latest&amp;#039; locally&lt;br /&gt;
 latest: Pulling from nicolaka/netshoot&lt;br /&gt;
 cbdbe7a5bc2a: Pull complete &lt;br /&gt;
 fa7edde5704a: Pull complete &lt;br /&gt;
 d142e371ed28: Pull complete &lt;br /&gt;
 7bc9cb006bce: Pull complete &lt;br /&gt;
 a4d2c327d444: Pull complete &lt;br /&gt;
 428e55c983a8: Pull complete &lt;br /&gt;
 1209022df24d: Pull complete &lt;br /&gt;
 b74093e72c31: Pull complete &lt;br /&gt;
 Digest: sha256:04786602e5a9463f40da65aea06fe5a825425c7df53b307daa21f828cfe40bf8&lt;br /&gt;
 Status: Downloaded newer image for nicolaka/netshoot:latest&lt;br /&gt;
                     dP            dP                           dP   &lt;br /&gt;
                     88            88                           88   &lt;br /&gt;
 88d888b. .d8888b. d8888P .d8888b. 88d888b. .d8888b. .d8888b. d8888P &lt;br /&gt;
 88&amp;#039;  `88 88ooood8   88   Y8ooooo. 88&amp;#039;  `88 88&amp;#039;  `88 88&amp;#039;  `88   88    &lt;br /&gt;
 88    88 88.  ...   88         88 88    88 88.  .88 88.  .88   88   &lt;br /&gt;
 dP    dP `88888P&amp;#039;   dP   `88888P&amp;#039; dP    dP `88888P&amp;#039; `88888P&amp;#039;   dP   &lt;br /&gt;
                                                                     &lt;br /&gt;
 Welcome to Netshoot! (github.com/nicolaka/netshoot)                                                                   &lt;br /&gt;
 root @ / &lt;br /&gt;
  [1] 🐳  →&lt;br /&gt;
&lt;br /&gt;
* The Netshoot container is launch as an interactive shell, and is started in the same network namespace as your nginx container. &lt;br /&gt;
* Netshoot is loaded with tools such as iperf, tcpdump, and other troubleshooting tools. That way you won&amp;#039;t have to load up your nginx container image as you want to keep it lightweight.&lt;br /&gt;
* Once you &amp;lt;b&amp;gt;exit&amp;lt;/b&amp;gt; the container, the container will stop. It only runs when your in the container. See &amp;lt;b&amp;gt;$ docker ps -a&amp;lt;/b&amp;gt; to view the stopped Netshoot container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;How to check iptables for the container port mapping information&amp;lt;/u&amp;gt;====&lt;br /&gt;
 $ sudo iptables -t nat -L -n&lt;br /&gt;
 Chain PREROUTING (policy ACCEPT)&lt;br /&gt;
 target     prot opt source               destination         &lt;br /&gt;
 DOCKER     all  --  0.0.0.0/0            0.0.0.0/0            ADDRTYPE match dst-type LOCAL&lt;br /&gt;
 DNAT       tcp  --  0.0.0.0/0            169.254.170.2        tcp dpt:80 to:127.0.0.1:51679&lt;br /&gt;
 &lt;br /&gt;
 Chain INPUT (policy ACCEPT)&lt;br /&gt;
 target     prot opt source               destination         &lt;br /&gt;
 &lt;br /&gt;
 Chain OUTPUT (policy ACCEPT)&lt;br /&gt;
 target     prot opt source               destination         &lt;br /&gt;
 DOCKER     all  --  0.0.0.0/0           !127.0.0.0/8          ADDRTYPE match dst-type LOCAL&lt;br /&gt;
 REDIRECT   tcp  --  0.0.0.0/0            169.254.170.2        tcp dpt:80 redir ports 51679 &lt;br /&gt;
 &lt;br /&gt;
 Chain POSTROUTING (policy ACCEPT)&lt;br /&gt;
 target     prot opt source               destination         &lt;br /&gt;
 MASQUERADE  all  --  172.17.0.0/16        0.0.0.0/0           &lt;br /&gt;
 MASQUERADE  tcp  --  172.17.0.3           172.17.0.3           tcp dpt:80&lt;br /&gt;
 MASQUERADE  tcp  --  172.17.0.4           172.17.0.4           tcp dpt:80  &lt;br /&gt;
 &lt;br /&gt;
 Chain DOCKER (2 references)&lt;br /&gt;
 target     prot opt source               destination         &lt;br /&gt;
 RETURN     all  --  0.0.0.0/0            0.0.0.0/0           &lt;br /&gt;
 DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:8080 to:172.17.0.3:80&lt;br /&gt;
 DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:8181 to:172.17.0.4:80&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;How to list docker networks&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
 $ docker network ls&lt;br /&gt;
 NETWORK ID          NAME                DRIVER              SCOPE&lt;br /&gt;
 86dc53b80450        bridge              bridge              local&lt;br /&gt;
 a8decea1c41f        host                host                local&lt;br /&gt;
 cb822f1d004d        none                null                local&lt;br /&gt;
&lt;br /&gt;
Then you can run the below command to check a lot of networking information such as driver, subnet, mac addresses, ipv4 addresses, etc. &lt;br /&gt;
 $ docker inspect 86dc53b80450&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;How to create docker volume&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
To create a volume: &amp;lt;b&amp;gt;$ docker volume create &amp;lt;volname&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;
 $ docker volume create my-vol&lt;br /&gt;
 my-vol&lt;br /&gt;
&lt;br /&gt;
To list volumes: &amp;lt;b&amp;gt;$ docker volume ls&amp;lt;/b&amp;gt;&lt;br /&gt;
 $ docker volume ls&lt;br /&gt;
 DRIVER              VOLUME NAME&lt;br /&gt;
 local               my-vol&lt;br /&gt;
&lt;br /&gt;
To start container with volume:&lt;br /&gt;
* Here you are mounting &amp;lt;i&amp;gt;my-vol&amp;lt;/i&amp;gt; volume to &amp;lt;i&amp;gt;/app&amp;lt;/i&amp;gt; inside of the container. &lt;br /&gt;
 $ docker run -d --name devtest --mount source=my-vol,target=/app nginx:latest&lt;br /&gt;
 2b8b4734db022263319b8c11c2760f685304a291e22d1683dd1ffe7c073256c7&lt;br /&gt;
&lt;br /&gt;
Docker volumes are located in: &amp;lt;b&amp;gt;/var/lib/docker/volumes/&amp;lt;volume_name&amp;gt;/_data/&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check volume mount point:&lt;br /&gt;
 # docker inspect my-vol&lt;br /&gt;
 [&lt;br /&gt;
     {&lt;br /&gt;
         &amp;quot;CreatedAt&amp;quot;: &amp;quot;2020-09-10T00:56:37Z&amp;quot;,&lt;br /&gt;
         &amp;quot;Driver&amp;quot;: &amp;quot;local&amp;quot;,&lt;br /&gt;
         &amp;quot;Labels&amp;quot;: {},&lt;br /&gt;
         &amp;quot;Mountpoint&amp;quot;: &amp;quot;/var/lib/docker/volumes/my-vol/_data&amp;quot;,&lt;br /&gt;
         &amp;quot;Name&amp;quot;: &amp;quot;my-vol&amp;quot;,&lt;br /&gt;
         &amp;quot;Options&amp;quot;: {},&lt;br /&gt;
         &amp;quot;Scope&amp;quot;: &amp;quot;local&amp;quot;&lt;br /&gt;
     }&lt;br /&gt;
 ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;How to start a container with a bind mount&amp;lt;/u&amp;gt;====&lt;br /&gt;
 $ docker run -d -it --name devtest --mount type=bind,source=&amp;quot;$(pwd)&amp;quot;/target,target=/app nginx:latest&lt;br /&gt;
* The location that your binding must exist or else you&amp;#039;ll get an error.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====&amp;lt;u&amp;gt;How to start a container with a tmpfs mount&amp;lt;/u&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
 $ docker run -d -it --name -tmptest --mount type=tmpfs,destination=/app nginx:latest&lt;br /&gt;
 324237498939b797989B979237923f&lt;/div&gt;</summary>
		<author><name>Ardika Sulistija</name></author>
	</entry>
</feed>