<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Naveen</title>
    <description>The latest articles on DEV Community by Naveen (@naveenvv).</description>
    <link>https://dev.to/naveenvv</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F524802%2Fa4a65d33-3c19-4079-8246-ba40dbbea1f8.png</url>
      <title>DEV Community: Naveen</title>
      <link>https://dev.to/naveenvv</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/naveenvv"/>
    <language>en</language>
    <item>
      <title>Docker CLI Cheat Sheet...</title>
      <dc:creator>Naveen</dc:creator>
      <pubDate>Thu, 18 Feb 2021 17:18:43 +0000</pubDate>
      <link>https://dev.to/naveenvv/docker-cli-cheat-sheet-42bb</link>
      <guid>https://dev.to/naveenvv/docker-cli-cheat-sheet-42bb</guid>
      <description>&lt;p&gt;Hey, You found it !...  Didn’t thought you would run into my first post/blog which I would like to share with you. Hope this post satisfies what you been searching for..&lt;/p&gt;

&lt;p&gt;Here are the commands which is use a lot. Continuing the post considering u have already installed the docker in your environment.&lt;/p&gt;

&lt;p&gt;Table of content 📎&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Docker Images&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Pull
&lt;/li&gt;
&lt;li&gt;
Search
&lt;/li&gt;
&lt;li&gt;
Create new image
&lt;/li&gt;
&lt;li&gt;
Build
&lt;/li&gt;
&lt;li&gt;
Pushing
&lt;/li&gt;
&lt;li&gt;
Remove
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Docker Container&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Create &lt;/li&gt;
&lt;li&gt;
Run &lt;/li&gt;
&lt;li&gt;
Update &lt;/li&gt;
&lt;li&gt;
Rename
&lt;/li&gt;
&lt;li&gt;Start Stop Restart&lt;/li&gt;
&lt;li&gt;Pause Resume&lt;/li&gt;
&lt;li&gt;Remove&lt;/li&gt;
&lt;li&gt;Info's&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Docker Network&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Create &lt;/li&gt;
&lt;li&gt;
List &lt;/li&gt;
&lt;li&gt;
Inspect &lt;/li&gt;
&lt;li&gt;
Remove &lt;/li&gt;
&lt;li&gt;
Connect Disconnect &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Docker Images &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Pull image from Docker Hub &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;To pull the Docker image available in docker hub repository. Image includes all the open-source images and your custom images.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;docker pull&lt;/code&gt; &lt;strong&gt;&lt;code&gt;imageName&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;docker pull naveenv24/hello_world&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Search &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;To search for any image available in docker hub includes additional filter option.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;docker search&lt;/code&gt; &lt;strong&gt;&lt;code&gt;imageName&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;docker search naveenv24/hello_world&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Create new image &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;All images which are created is dependent on the base image eg. alpine image. If we name the file as Dockerfile by default docker picks up the file to perform actions related to the image&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;FROM alpine:3.7&lt;br&gt;
RUN apk add --no-cache mysql-client&lt;br&gt;
ENTRYPOINT ["mysql"]&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h4&gt;
  
  
  Build an image &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;docker build .&lt;/code&gt;&lt;/strong&gt; (OR) &lt;strong&gt;&lt;code&gt;docker build dir/pathto/&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker build -f&lt;/code&gt; &lt;strong&gt;&lt;code&gt;Dockerfile&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker build -f Dockerfile.renamed&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Pushing the image &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;This is used to push your new or any updated image to the docker hub. Perquisite is the docker login to the registry.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;docker push&lt;/code&gt; &lt;strong&gt;&lt;code&gt;imageNameToBeUploaded&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker push naveenv24/hello_world&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Removing the image &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;This command will help you remove the image from your environment if it’s not having any dependency. Include &lt;code&gt;-f&lt;/code&gt; to forcefully remove. &lt;code&gt;rmi&lt;/code&gt; implies remove-image.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;docker rmi -f&lt;/code&gt; &lt;strong&gt;&lt;code&gt;imageName&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker rmi naveenv24/hello_world&lt;/code&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Docker Container &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Creating a container &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;This command will create writable container over the specified image. This command will only create the container but will not run/start it. &lt;code&gt;-t&lt;/code&gt; implies target &lt;code&gt;-I&lt;/code&gt; implies the image name. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;docker create – t  -I&lt;/code&gt; &lt;strong&gt;&lt;code&gt;ImageName&lt;/code&gt;&lt;/strong&gt;  &lt;code&gt;--name&lt;/code&gt; &lt;strong&gt;&lt;code&gt;ContainerName&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker create – t  -I naveenv24/hello_world --name hw-container&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Running the container &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;This command will create the container if not created and starts the container the &lt;code&gt;-it&lt;/code&gt; implies interactive mode and &lt;code&gt;-d&lt;/code&gt; implies detach mode which run the container background&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;docker run –name&lt;/code&gt; &lt;strong&gt;&lt;code&gt;containerName&lt;/code&gt;&lt;/strong&gt;  &lt;code&gt;-it -d imageName&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker run –name hw-container -it -d naveenv24/hello_world&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Renaming the container &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;This command will rename you’re container name &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;docker rename&lt;/code&gt; &lt;strong&gt;&lt;code&gt;oldContainerName&lt;/code&gt;&lt;/strong&gt; &lt;strong&gt;&lt;code&gt;newContainerName&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker rename hw-container hw-con-new&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Updating the container &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;To update any container related configuration update command is used. Configuration more related to the CPU, memory etc. , Note: currently not available in windows at the time of this been posted.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;docker run -dit –name containerName –kernel-memory 50M ubuntu bash&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker update –kernel-memory 100M  containerName&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Container Start, Stop and Restart &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;Stop the running container or start the non running container or use restart to perform both. &lt;code&gt;-t&lt;/code&gt; wait time before killing the container.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;docker stop&lt;/code&gt; &lt;strong&gt;&lt;code&gt;containerName&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;docker stop hw-con-new&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker start&lt;/code&gt; &lt;strong&gt;&lt;code&gt;containerName&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;docker start hw-con-new&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker restart -t&lt;/code&gt; &lt;strong&gt;&lt;code&gt;containerName&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;docker restart -t hw-con-new&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Pausing and Resuming &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;To suspend any process running in the container temporarily and to un-suspend the process again.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;docker pause&lt;/code&gt; &lt;strong&gt;&lt;code&gt;containerName&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;docker pause hw-con-new&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker unpause&lt;/code&gt; &lt;strong&gt;&lt;code&gt;containerName&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;docker unpause hw-con-new&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Removing the container &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;To remove the one or more container. To remove the container forcefully add -f or –force.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;docker rm -v  -f&lt;/code&gt; &lt;strong&gt;&lt;code&gt;containerName&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;docker rm -v  -f hw-con-new&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Information’s related to Container &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;Listed commands will provide info related to container or process running In the container.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;docker ps&lt;/code&gt; &amp;gt; will show all the active running container (-a includes remaining available container)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker logs hw-con-new&lt;/code&gt; &amp;gt;&amp;gt; gets logs from container. (You can use a custom log driver, but logs is only available for json-file and journald in 1.10).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker inspect hw-con-new&lt;/code&gt; &amp;gt;&amp;gt; displays all the info related to container includes the ips and ports related details`&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker port hw-con-new&lt;/code&gt;&amp;gt;&amp;gt; shows all the ports running in the container`&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker stats hw-con-new&lt;/code&gt; &amp;gt;&amp;gt;  Display a live stream of container(s) resource usage statistics&lt;/p&gt;




&lt;h3&gt;
  
  
  Docker Networks &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Creating a Network &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;To create a network by default will create a bridge network, to specify a network type use -d (driver) option along with the command.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;docker network create -d&lt;/code&gt; &lt;strong&gt;&lt;code&gt;bridge&lt;/code&gt;&lt;/strong&gt; &lt;strong&gt;&lt;code&gt;networkName&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker network create -d bridge mynetwork&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Listing all Network &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;To view all the available networks in the docker&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;docker network ls&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Inspecting a Network &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;To view the detailed information about the network&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;docker network inspect&lt;/code&gt; &lt;strong&gt;&lt;code&gt;networkName&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;docker network inspect mynetwork&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Removing &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;To remove the network from the available list&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;docker network rm&lt;/code&gt; &lt;strong&gt;&lt;code&gt;networkName&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;docker network rm mynetwork&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Connect &amp;amp; Disconnecting container from a network &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;To connect the container from the network&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;docker network connect&lt;/code&gt; &lt;strong&gt;&lt;code&gt;networkName containerName&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;docker network connect mynetwork hw-con-new&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To disconnect the container from the network&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;docker network disconnect&lt;/code&gt; &lt;strong&gt;&lt;code&gt;networkName containerName&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;docker network disconnect mynetwork hw-con-new&lt;/code&gt;&lt;/p&gt;




&lt;p&gt;These are all the command we will frequently looking into when any implementation is undergone. &lt;/p&gt;

&lt;p&gt;Though it might seem few these are basically enough to perform and docker build with multiple services connected through.. 🚀&lt;/p&gt;

&lt;p&gt;Appreciate spending your time on this. Hope you liked it.. Share your thoughts this might be useful for improving the quality. 🍻&lt;/p&gt;

</description>
      <category>docker</category>
      <category>dockercompose</category>
      <category>devops</category>
      <category>cheatsheet</category>
    </item>
  </channel>
</rss>
