{"id":192343,"date":"2021-03-02T18:00:27","date_gmt":"2021-03-02T15:00:27","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/kubernetes-alternatives-to-docker-commands-cloudsavvy-it\/"},"modified":"2021-03-02T18:00:27","modified_gmt":"2021-03-02T15:00:27","slug":"kubernetes-alternatives-to-docker-commands-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/kubernetes-alternatives-to-docker-commands-cloudsavvy-it\/","title":{"rendered":"#Kubernetes Alternatives to Docker Commands \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2e1c58bdb2e\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2e1c58bdb2e\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/kubernetes-alternatives-to-docker-commands-cloudsavvy-it\/#Getting_Details_of_Your_Containers\" >Getting Details of Your Containers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/kubernetes-alternatives-to-docker-commands-cloudsavvy-it\/#Executing_Commands_in_Containers\" >Executing Commands in Containers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/kubernetes-alternatives-to-docker-commands-cloudsavvy-it\/#Viewing_Container_Logs\" >Viewing Container Logs<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/kubernetes-alternatives-to-docker-commands-cloudsavvy-it\/#Creating_Containers\" >Creating Containers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/kubernetes-alternatives-to-docker-commands-cloudsavvy-it\/#Removing_Containers\" >Removing Containers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/buradabiliyorum.com\/en\/kubernetes-alternatives-to-docker-commands-cloudsavvy-it\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#Kubernetes Alternatives to Docker Commands \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9632\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/06268c7060f33c17d0b8db5f1f90faf9\/p\/uploads\/2021\/02\/748108a6.jpg\" alt=\"Graphic showing the Kubernetes logo\" width=\"1602\" height=\"902\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Docker usually provides a developer\u2019s first introduction to containers. Kubernetes is an orchestration platform which solves challenges around running containers in production. Here\u2019s how Docker commands map to their Kubernetes counterparts.<\/p>\n<p>You can\u2019t use the <code>docker<\/code> CLI to interact with containers running in Kubernetes. Kubernetes provides its own command-line interface, <code>kubectl<\/code>, to help you manage your cluster. Read our guide to getting started with <code>kubectl<\/code> if you\u2019re unfamiliar with the tool.<\/p>\n<p>None of the <code>docker<\/code> commands have the same name in <code>kubectl<\/code>. Kubernetes exposes functionality in its own way. Workloads themselves are fundamentally different \u2013 Docker is designed to work with a single container at a time, whereas Kubernetes enables orchestration of multiple replicas.<\/p>\n<p>The first point to <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">app<\/a>reciate is the shift in terminology. Docker refers to \u201ccontainers\u201d while Kubernetes uses \u201cpods\u201d. A pod might run one container or multiple replicas managed as a single unit. This detail aside, when you see \u201ccontainer\u201d in Docker, you should think of a Kubernetes \u201cpod\u201d. The terms will be used interchangeably for the remainder of this article.<\/p>\n<h2 id=\"getting-details-of-your-containers\"><span class=\"ez-toc-section\" id=\"Getting_Details_of_Your_Containers\"><\/span>Getting Details of Your Containers<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In Docker, you use <code>docker ps -a<\/code> to see all the containers on your machine.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9790\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/6fb7d5326bafb236690dea7510e4df3c\/p\/uploads\/2021\/02\/f3ccdd27-2.jpg\" alt=\"\" width=\"842\" height=\"292\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>The closest Kubernetes equivalent is <code>kubectl get pods<\/code>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9791\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/8df479615e9159b7700e3bc069a3eac9\/p\/uploads\/2021\/02\/156005c5-2.jpg\" alt=\"\" width=\"993\" height=\"95\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>The output from the two commands is quite different. Docker shows more information about the workload the container is running.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9792\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/c5cda7ab7bd6369851169ab7742f04e2\/p\/uploads\/2021\/02\/799bad5a-1.jpg\" alt=\"\" width=\"967\" height=\"542\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Kubernetes will provide details about image and command when using the <code>describe pod<\/code> command. You need to pass the name of the pod. This gives much more verbose information, using a list instead of a table.<\/p>\n<h2 id=\"executing-commands-in-containers\"><span class=\"ez-toc-section\" id=\"Executing_Commands_in_Containers\"><\/span>Executing Commands in Containers<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Docker lets you execute a command in a running container using <code>docker exec<\/code>.<\/p>\n<p>The Kubernetes equivalent is also called <code>exec<\/code>. Use the Kubernetes pod name instead of the Docker container name. The command is specified slightly differently \u2013 it must be separated from the pod name by a <code>--<\/code> sequence.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9793\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/e3dbc9817e41078251ec216d173d83e4\/p\/uploads\/2021\/02\/a7ee5674.jpg\" alt=\"\" width=\"965\" height=\"150\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You can use the <code>-it<\/code> flags to obtain interactive access in the same way as Docker. This is a shorthand for <code>--stdin --tty<\/code> and should be used whenever you want to launch a shell within a pod. Specify the shell name, such as <code>bash<\/code>, as the command.<\/p>\n<p>Kubectl supports the <code>attach<\/code> command for when you want to attach to a process in a container that\u2019s already running. It works similarly to <code>docker attach<\/code> but you should pass the <code>-it<\/code> flags if you need interactive access.<\/p>\n<h2 id=\"viewing-container-logs\"><span class=\"ez-toc-section\" id=\"Viewing_Container_Logs\"><\/span>Viewing Container Logs<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To view a container\u2019s logs with Docker, you use the <code>docker logs<\/code> command. Adding the <code>-f<\/code> switch will \u201cfollow\u201d the logs so they\u2019re streamed continuously to your terminal.<\/p>\n<p>Kubectl\u2019s <code>logs<\/code> command has the same syntax. Supply a pod name in the same way Docker accepts a container name.<\/p>\n<p>Both Docker and Kubernetes collect logs from the standard output and standard error (<code>stdout<\/code>\/<code>stderr<\/code>) streams of running containers. Kubernetes handles container restarts differently to Docker. Whereas in Docker a restarted container appends its logs to the existing ones, Kubernetes creates a new log for each run. You can get the logs of a replaced container by adding the <code>--previous<\/code> flag to the <code>logs<\/code> command.<\/p>\n<h2 id=\"creating-containers\"><span class=\"ez-toc-section\" id=\"Creating_Containers\"><\/span>Creating Containers<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Docker containers are created with the <code>run<\/code> command. Here\u2019s how you could start an <code>nginx<\/code> server with Docker:<\/p>\n<pre>docker run -d --name nginx --restart=always -p 80:80 nginx<\/pre>\n<p>This creates a container using the <code>nginx<\/code> base image and sets it to restart automatically. The server is bound to the default HTTP port 80.<\/p>\n<p>Kubernetes requires you to think of higher-level abstractions when adding containers to your cluster. Instead of running a container, you\u2019re creating a <em>deployment<\/em> to represent your workload:<\/p>\n<pre>kubectl create deployment --image=nginx nginx<\/pre>\n<p>This will create an <code>nginx<\/code> deployment. A pod gets started automatically; within the pod, there\u2019ll be a container running the web server.<\/p>\n<p>Creating a deployment won\u2019t bind its containers to any ports. The newly created server isn\u2019t yet accessible. Ports must be <em>exposed<\/em> via a <em>service<\/em>. Pods are ephemeral and may contain multiple replicated containers. Services define a logical collection of pods and let you assign them network resources such as an IP address and port.<\/p>\n<p>Exposing the <code>nginx<\/code> deployment on port 80 will enable the server to be accessed:<\/p>\n<pre>kubectl expose deployment nginx --port=80 --name nginx-http<\/pre>\n<p>Trying to access port 80 on the cluster\u2019s default IP address should now direct you to the <code>nginx<\/code> server.<\/p>\n<p>Kubectl doesn\u2019t directly support other <code>docker run<\/code> options such as volume creation and bind mounts. Containers that require persistent storage will need to have volumes configured manually via <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/cheatsheet\"><code>kubectl<\/code> commands<\/a> or a <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/kubernetes.io\/docs\/tasks\/configure-pod-container\/configure-volume-storage\">volume manifest<\/a>.<\/p>\n<h2 id=\"removing-containers\"><span class=\"ez-toc-section\" id=\"Removing_Containers\"><\/span>Removing Containers<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Docker containers are removed using the <code>docker rm<\/code> command with the container\u2019s ID.<\/p>\n<p>Kubernetes doesn\u2019t let you delete containers directly. Instead, you work with the <em>deployment<\/em> which created the pod. Use the <code>kubectl delete deployment<\/code> command, passing the deployment\u2019s name.<\/p>\n<p>Docker allows you to <em>stop<\/em> a container instead of removing it. Kubernetes has removed support for this action. The recommended way to temporarily suspend a deployment is to scale its replica count down to 0. With no pods running, the workload is effectively stopped.<\/p>\n<pre>kubectl scale --replicas=0 deployment\/my-deployment<\/pre>\n<p>When you\u2019re ready to resume the deployment, run the <code>scale<\/code> command again. Set the new replica count to <code>1<\/code> or higher. Using more replicas can increase the availability of your workload.<\/p>\n<h2 id=\"conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>There\u2019s no direct parallels between the Docker CLI and <code>kubectl<\/code>. Most of the Kubernetes commands have a different syntax to their Docker counterparts. You will need to learn new terms and options before you can transition Docker-based workflows onto Kubernetes.<\/p>\n<p>In many cases, there is no <code>kubectl<\/code> alternative to a Docker CLI capability. Docker\u2019s functionality is focused on the container concept. Kubernetes takes that and places it at the centre of a greatly expanded resource ecosystem.<\/p>\n<p>Containers are rarely dealt with in isolation. Instead, you\u2019ll need to work with resources such as deployments, services and replica sets. This is why learning Kubernetes can seem challenging when approaching it from the perspective of a Docker user.<\/p>\n<p>If you\u2019re familiar with Docker fundamentals, transitioning to Kubernetes should nonetheless be relatively straightforward. The principle difference is that what Docker sees as a container is usually accessed as an aggregate \u201cpod\u201d in Kubernetes. Pods are created by \u201cdeployments\u201d which represent the workloads in your cluster. When in doubt, refer to the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/kubernetes.io\/docs\/reference\/kubectl\/docker-cli-to-kubectl\"><code>kubectl<\/code> docs<\/a> to find an approriate match for a Docker command.\n<\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/9783\/kubernetes-alternatives-to-docker-commands\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#Kubernetes Alternatives to Docker Commands \u2013 CloudSavvy IT&#8221; Docker usually provides a developer\u2019s first introduction to containers. Kubernetes is an orchestration platform which solves challenges around running containers in production. Here\u2019s how Docker commands map to their Kubernetes counterparts. You can\u2019t use the docker CLI to interact with containers running in Kubernetes. Kubernetes provides its&#8230;<\/p>\n","protected":false},"author":1,"featured_media":192344,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/06268c7060f33c17d0b8db5f1f90faf9\/p\/uploads\/2021\/02\/748108a6.jpg","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-192343","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/192343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=192343"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/192343\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/192344"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=192343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=192343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=192343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}