<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>env - Tag - Coding Life Share</title><link>https://blog.xwi88.com/en/tags/env/</link><description>env - Tag - Coding Life Share</description><generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>278810732@qq.com (xwi88)</managingEditor><webMaster>278810732@qq.com (xwi88)</webMaster><copyright>This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.</copyright><lastBuildDate>Fri, 11 Mar 2022 21:27:21 +0800</lastBuildDate><atom:link href="https://blog.xwi88.com/en/tags/env/" rel="self" type="application/rss+xml"/><item><title>Replacing Docker Desktop with minikube on Mac</title><link>https://blog.xwi88.com/en/mac-minikube-replace-docker-desktop/</link><pubDate>Fri, 11 Mar 2022 21:27:21 +0800</pubDate><author>xwi88</author><guid>https://blog.xwi88.com/en/mac-minikube-replace-docker-desktop/</guid><description><![CDATA[<p>On <strong><a href="https://www.docker.com/blog/updating-product-subscriptions/" target="_blank" rel="noopener noreffer ">2021-08-31 Docker announced</a></strong> that <a href="https://www.docker.com/products/docker-desktop" target="_blank" rel="noopener noreffer ">Docker Desktop</a> would no longer be free for larger organizations. So we need a convenient replacement for <code>Docker Desktop</code> with minimal disruption — such as <a href="https://minikube.sigs.k8s.io/docs/" target="_blank" rel="noopener noreffer ">minikube</a>, <a href="https://github.com/moby/hyperkit" target="_blank" rel="noopener noreffer ">Hyperkit</a>, or <a href="https://podman.io/" target="_blank" rel="noopener noreffer ">podman</a>.</p>
<blockquote>
<p><strong>Copyright notice</strong>: This is an original article by <strong><a href="https://github.com/xwi88" target="_blank" rel="noopener noreffer ">xwi88</a></strong>, licensed under <a href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank" rel="noopener noreffer ">CC BY-NC 4.0</a>. Commercial use is prohibited; please cite the source when reposting. Follow at <a href="https://github.com/xwi88" target="_blank" rel="noopener noreffer ">https://github.com/xwi88</a></p>
</blockquote>
<h2 id="terminology">
    <a href="#terminology" class="header-anchor" aria-label="Link to Terminology"></a>Terminology</h2>
<ul>
<li><strong><a href="https://en.wikipedia.org/wiki/Docker,_Inc." target="_blank" rel="noopener noreffer ">Docker Inc</a></strong> a US-based company that built open-source and closed-source software making it easier to develop, test, and run applications in containers.</li>
<li><strong><a href="https://github.com/docker/engine" target="_blank" rel="noopener noreffer ">Docker Engine</a></strong> the core technology behind Docker. Open-source software that runs as a daemon on Linux and makes running containers on the Linux kernel possible. It owns the container lifecycle and the isolation of physical resources (compute, memory, storage) a container can access. It can run on physical or virtual machines, but only on a Linux kernel — i.e. on any Linux-flavored OS. This is important: <strong>the Docker engine runs only on Linux</strong>.</li>
<li><strong><a href="https://github.com/docker/cli" target="_blank" rel="noopener noreffer ">Docker CLI</a></strong> <em>CLI</em> that developers usually use to interact with the docker engine. Includes the <code>docker</code> and <code>docker-compose</code> commands. Again, open source.</li>
<li><strong><a href="https://www.docker.com/products/docker-desktop" target="_blank" rel="noopener noreffer ">Docker Desktop</a></strong> since Docker Engine runs only on Linux, developers on Windows and macOS can only run the engine after starting a Linux VM. That&rsquo;s where Docker Desktop comes in. Docker Desktop is proprietary software that lets Windows/macOS developers use containers seamlessly in dev without managing VMs and all the details that entails (networking, virtualization, Linux knowledge, …). Docker Desktop is designed for use during software development; <em>it has no place in production-like containers</em>, where only <code>Docker Engine</code> is involved.</li>
</ul>
<div class="details admonition tip open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-lightbulb fa-fw" aria-hidden="true"></i>Tip<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content">The way to keep running and building container apps on <strong>macOS</strong> is to run <code>Docker Engine</code> inside a <code>Linux VM</code>.</div>
        </div>
    </div>
<h2 id="requirements">
    <a href="#requirements" class="header-anchor" aria-label="Link to Requirements"></a>Requirements</h2>
<ul>
<li>At least 2 CPUs</li>
<li>At least 2 GB of free memory</li>
<li>At least 20 GB of free disk space</li>
<li>A network connection</li>
<li>A container or VM manager, e.g. <strong><a href="https://docs.docker.com/get-docker/" target="_blank" rel="noopener noreffer ">Docker</a></strong>, <strong><a href="https://github.com/moby/hyperkit" target="_blank" rel="noopener noreffer ">Hyperkit</a></strong>, Hyper-V, KVM, Parallels, <strong><a href="https://podman.io/" target="_blank" rel="noopener noreffer ">podman</a></strong>, <em><a href="https://www.virtualbox.org/" target="_blank" rel="noopener noreffer ">VirtualBox</a></em>, or VMware Fusion/Workstation</li>
</ul>
<h2 id="installation">
    <a href="#installation" class="header-anchor" aria-label="Link to Installation"></a>Installation</h2>
<blockquote>
<p>If you&rsquo;re sure you won&rsquo;t run images in <code>docker desktop</code> anymore, remove all <code>docker</code> / <code>docker desktop</code> related config.</p>
</blockquote>
<div class="details admonition example open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-list-ol fa-fw" aria-hidden="true"></i>Example<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content"><blockquote>
<p><a href="https://brew.sh/" target="_blank" rel="noopener noreffer ">Homebrew</a> install recommended</p>
</blockquote>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">brew install docker
</span></span><span class="line"><span class="cl">brew install docker-compose <span class="c1"># optional, as needed</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">brew install hyperkit
</span></span><span class="line"><span class="cl">brew install minikube
</span></span></code></pre></td></tr></table>
</div>
</div><div class="details admonition tip open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-lightbulb fa-fw" aria-hidden="true"></i>Tip<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content"><p>If installing <code>minikube</code> via <em>brew</em> fails, try a manual install</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-amd64
</span></span><span class="line"><span class="cl">sudo install minikube-darwin-amd64 /usr/local/bin/minikube
</span></span></code></pre></td></tr></table>
</div>
</div></div>
        </div>
    </div>
</div>
        </div>
    </div>
<h2 id="verify-the-install">
    <a href="#verify-the-install" class="header-anchor" aria-label="Link to Verify the install"></a>Verify the install</h2>
<p>Run <code>which minikube</code></p>
<div class="details admonition warning open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-exclamation-triangle fa-fw" aria-hidden="true"></i>Warning<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content"><p>After a <em>brew</em> install, if <code>which minikube</code> fails, run:</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">brew unlink minikube
</span></span><span class="line"><span class="cl">brew link minikube
</span></span></code></pre></td></tr></table>
</div>
</div><p><em>remove the old minikube links and link the newly installed binary</em></p>
</div>
        </div>
    </div>
<h2 id="drivers">
    <a href="#drivers" class="header-anchor" aria-label="Link to Drivers"></a>Drivers</h2>
<blockquote>
<p><code>minikube</code> needs a <code>Linux VM</code> to start on <code>mac/windows</code>; that&rsquo;s the driver we configure. With <code>--driver=docker</code> you need the matching <code>Docker Desktop</code> installed to reuse its <code>linux vm</code>.
Otherwise pick another driver. Supported drivers:</p>
</blockquote>
<h3 id="linux">
    <a href="#linux" class="header-anchor" aria-label="Link to Linux"></a><em>Linux</em></h3>
<ul>
<li><strong><a href="https://minikube.sigs.k8s.io/docs/drivers/docker/" target="_blank" rel="noopener noreffer ">Docker</a></strong> - container-based (preferred)</li>
<li>KVM2 - VM-based (preferred)</li>
<li>VirtualBox - VM</li>
<li><strong><a href="https://minikube.sigs.k8s.io/docs/drivers/none/" target="_blank" rel="noopener noreffer ">None</a></strong> - bare-metal</li>
<li><strong><a href="https://minikube.sigs.k8s.io/docs/drivers/podman/" target="_blank" rel="noopener noreffer ">Podman</a></strong> - container (experimental)</li>
<li>SSH - remote ssh</li>
</ul>
<h3 id="macos">
    <a href="#macos" class="header-anchor" aria-label="Link to macOS"></a><strong>macOS</strong></h3>
<ul>
<li><em><a href="https://minikube.sigs.k8s.io/docs/drivers/docker/" target="_blank" rel="noopener noreffer ">Docker</a></em> - VM + Container (preferred)</li>
<li><strong><a href="https://minikube.sigs.k8s.io/docs/drivers/hyperkit/" target="_blank" rel="noopener noreffer ">Hyperkit</a></strong> - VM</li>
<li>VirtualBox - VM</li>
<li>Parallels - VM</li>
<li>VMware Fusion - VM</li>
<li>SSH - remote ssh</li>
</ul>
<h3 id="windows">
    <a href="#windows" class="header-anchor" aria-label="Link to Windows"></a>Windows</h3>
<ul>
<li><strong><a href="https://minikube.sigs.k8s.io/docs/drivers/hyperv/" target="_blank" rel="noopener noreffer ">Hyper-V</a></strong> - VM (preferred)</li>
<li><strong><a href="https://minikube.sigs.k8s.io/docs/drivers/docker/" target="_blank" rel="noopener noreffer ">Docker</a></strong> - VM + Container (preferred)</li>
<li>VirtualBox - VM</li>
<li>VMware Workstation - VM</li>
<li>SSH - remote ssh</li>
</ul>
<div class="details admonition warning open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-exclamation-triangle fa-fw" aria-hidden="true"></i>Warning<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content"><p>If you set <code>--driver=docker</code>, distinguish <strong><code>standard</code></strong> vs <strong><code>rootless</code></strong> docker</p>
<blockquote>
<p><strong>Standard Docker</strong></p>
</blockquote>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># need: install Docker 18.09 or higher</span>
</span></span><span class="line"><span class="cl"><span class="c1">#       amd64 or arm64 system.</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Start a cluster using the docker driver:</span>
</span></span><span class="line"><span class="cl">minikube start --driver<span class="o">=</span>docker
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># To make docker the default driver:</span>
</span></span><span class="line"><span class="cl">minikube config <span class="nb">set</span> driver docker
</span></span></code></pre></td></tr></table>
</div>
</div><blockquote>
<p><strong>Rootless Docker</strong></p>
</blockquote>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># Requirements</span>
</span></span><span class="line"><span class="cl"><span class="c1">#    Docker 20.10 or higher, see https://rootlesscontaine.rs/getting-started/docker/</span>
</span></span><span class="line"><span class="cl"><span class="c1">#    Cgroup v2 delegation, see https://rootlesscontaine.rs/getting-started/common/cgroup2/</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">dockerd-rootless-setuptool.sh install -f
</span></span><span class="line"><span class="cl">docker context use rootless
</span></span><span class="line"><span class="cl">minikube start --driver<span class="o">=</span>docker --container-runtime<span class="o">=</span>containerd
</span></span></code></pre></td></tr></table>
</div>
</div><blockquote>
<p>The <code>--container-runtime</code> flag must be set to <code>containerd</code> or <code>cri-o</code>.</p>
</blockquote>
</div>
        </div>
    </div>
<blockquote>
<p>More driver config &amp; usage: <a href="https://minikube.sigs.k8s.io/docs/drivers/" target="_blank" rel="noopener noreffer ">minikube drivers</a></p>
</blockquote>
<h2 id="config-commands">
    <a href="#config-commands" class="header-anchor" aria-label="Link to Config commands"></a>Config commands</h2>
<p><code>minikube config SUBCOMMAND [flags] [options]</code></p>
<ul>
<li><code>minikube config help</code></li>
<li><code>minikube config defaults PROPERTY_NAME [flags]</code> <em>list displays all valid default settings for PROPERTY_NAME</em></li>
<li><code>minikube config view [flags]</code> Display values currently set in the minikube config file.</li>
<li><code>minikube config set PROPERTY_NAME PROPERTY_VALUE [flags]</code> <em>Sets an individual value in a minikube config file</em></li>
<li><code>minikube config get PROPERTY_NAME [flags]</code> <em>Returns the value of PROPERTY_NAME from the minikube config file</em></li>
<li><code>minikube config unset PROPERTY_NAME [flags]</code> <em>unsets PROPERTY_NAME from the minikube config file.</em></li>
</ul>
<div class="details admonition tip open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-lightbulb fa-fw" aria-hidden="true"></i>Tip<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content"><blockquote>
<p><code>minikube config --help</code></p>
</blockquote>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span><span class="lnt">35
</span><span class="lnt">36
</span><span class="lnt">37
</span><span class="lnt">38
</span><span class="lnt">39
</span><span class="lnt">40
</span><span class="lnt">41
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-tex" data-lang="tex"><span class="line"><span class="cl">config modifies minikube config files using subcommands like &#34;minikube config set driver kvm2&#34;
</span></span><span class="line"><span class="cl">Configurable fields:
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"> * driver
</span></span><span class="line"><span class="cl"> * vm-driver
</span></span><span class="line"><span class="cl"> * container-runtime
</span></span><span class="line"><span class="cl"> * feature-gates
</span></span><span class="line"><span class="cl"> * v
</span></span><span class="line"><span class="cl"> * cpus
</span></span><span class="line"><span class="cl"> * disk-size
</span></span><span class="line"><span class="cl"> * host-only-cidr
</span></span><span class="line"><span class="cl"> * memory
</span></span><span class="line"><span class="cl"> * log<span class="nb">_</span>dir
</span></span><span class="line"><span class="cl"> * kubernetes-version
</span></span><span class="line"><span class="cl"> * iso-url
</span></span><span class="line"><span class="cl"> * WantUpdateNotification
</span></span><span class="line"><span class="cl"> * WantBetaUpdateNotification
</span></span><span class="line"><span class="cl"> * ReminderWaitPeriodInHours
</span></span><span class="line"><span class="cl"> * WantNoneDriverWarning
</span></span><span class="line"><span class="cl"> * WantVirtualBoxDriverWarning
</span></span><span class="line"><span class="cl"> * profile
</span></span><span class="line"><span class="cl"> * bootstrapper
</span></span><span class="line"><span class="cl"> * insecure-registry
</span></span><span class="line"><span class="cl"> * hyperv-virtual-switch
</span></span><span class="line"><span class="cl"> * disable-driver-mounts
</span></span><span class="line"><span class="cl"> * cache
</span></span><span class="line"><span class="cl"> * EmbedCerts
</span></span><span class="line"><span class="cl"> * native-ssh
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">Available Commands:
</span></span><span class="line"><span class="cl">  defaults    Lists all valid default values for PROPERTY<span class="nb">_</span>NAME
</span></span><span class="line"><span class="cl">  get         Gets the value of PROPERTY<span class="nb">_</span>NAME from the minikube config file
</span></span><span class="line"><span class="cl">  set         Sets an individual value in a minikube config file
</span></span><span class="line"><span class="cl">  unset       unsets an individual value in a minikube config file
</span></span><span class="line"><span class="cl">  view        Display values currently set in the minikube config file
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">Usage:
</span></span><span class="line"><span class="cl">  minikube config SUBCOMMAND [flags] [options]
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">Use &#34;minikube &lt;command&gt; --help&#34; for more information about a given command.
</span></span><span class="line"><span class="cl">Use &#34;minikube options&#34; for a list of global command-line options (applies to all commands).
</span></span></code></pre></td></tr></table>
</div>
</div></div>
        </div>
    </div>
<div class="details admonition example open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-list-ol fa-fw" aria-hidden="true"></i>Example<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content"><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">minikube config <span class="nb">set</span> driver hyperkit
</span></span><span class="line"><span class="cl">minikube config <span class="nb">set</span> cpus <span class="m">2</span>
</span></span><span class="line"><span class="cl">minikube config <span class="nb">set</span> memory 2000mb
</span></span><span class="line"><span class="cl">minikube config <span class="nb">set</span> disk-size 20gb
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># insecure-registry didn&#39;t take effect in testing; pass it at start time!</span>
</span></span><span class="line"><span class="cl">minikube config <span class="nb">set</span> insecure-registry https://docker.mirrors.ustc.edu.cn,https://reg-mirror.qiniu.com,https://mirror.ccs.tencentyun.com
</span></span><span class="line"><span class="cl"><span class="c1"># minikube config set kubernetes-version &lt;&gt;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># The name of the minikube VM being used. This can be set to allow having multiple instances of minikube independently. (default &#34;minikube&#34;)</span>
</span></span><span class="line"><span class="cl">minikube config <span class="nb">set</span> profile
</span></span></code></pre></td></tr></table>
</div>
</div></div>
        </div>
    </div>
<h2 id="quick-start">
    <a href="#quick-start" class="header-anchor" aria-label="Link to Quick start"></a>Quick start</h2>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">minikube start <span class="c1"># minikube start --container-runtime=docker</span>
</span></span><span class="line"><span class="cl"><span class="c1"># Tell Docker CLI to talk to minikube&#39;s VM</span>
</span></span><span class="line"><span class="cl"><span class="nb">eval</span> <span class="k">$(</span>minikube docker-env<span class="k">)</span>
</span></span><span class="line"><span class="cl"><span class="c1"># Save IP to a hostname</span>
</span></span><span class="line"><span class="cl"><span class="c1"># echo &#34;`minikube ip` docker.local&#34; | sudo tee -a /etc/hosts &gt; /dev/null</span>
</span></span><span class="line"><span class="cl"><span class="c1"># control panel, must start minikube with cluster model, without flag --no-kubernetes</span>
</span></span><span class="line"><span class="cl">minikube dashboard
</span></span><span class="line"><span class="cl"><span class="c1"># stop kubernetes related</span>
</span></span><span class="line"><span class="cl">minikube pause
</span></span><span class="line"><span class="cl"><span class="c1"># test</span>
</span></span><span class="line"><span class="cl">docker run hello-world
</span></span></code></pre></td></tr></table>
</div>
</div><h2 id="advanced-start">
    <a href="#advanced-start" class="header-anchor" aria-label="Link to Advanced start"></a>Advanced start</h2>
<blockquote>
<p><strong><a href="https://minikube.sigs.k8s.io/docs/commands/start/" target="_blank" rel="noopener noreffer ">commands start</a></strong></p>
</blockquote>
<h3 id="start-command">
    <a href="#start-command" class="header-anchor" aria-label="Link to Start command"></a>Start command</h3>
<ul>
<li>After some config changes you need <code>minikube delete</code> then restart</li>
</ul>
<div class="details admonition example open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-list-ol fa-fw" aria-hidden="true"></i>Example<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content"><p><code>minikube start --driver=hyperkit</code> or <code>minikube start --driver=docker</code> or another driver</p>
<p>A config like the following is recommended so you don&rsquo;t have to enter the <code>minikube vm</code> to change things later. Key options:</p>
<ul>
<li><strong><code>--insecure-registry</code></strong></li>
<li><em><code>--registry-mirror</code></em></li>
<li><em><code>--mount</code></em> <strong>mount a host directory into the <code>minikube vm</code></strong>
<ul>
<li>On MacOS, <code>/Users:/minikube-host/</code> is mounted by default</li>
<li><strong>Keep the mount path identical to avoid path-dependent programs failing to start</strong></li>
<li>Use <code>--mount-string</code> to mount on demand</li>
</ul>
</li>
<li><strong><code>--mount-string</code></strong> specify the mount directory</li>
<li><strong><code>--no-kubernetes</code></strong></li>
<li><strong><code>--cpus</code></strong></li>
<li><strong><code>--memory</code></strong></li>
<li><code>--image-mirror-country</code></li>
</ul>
<p><code>minikube start --no-kubernetes --registry-mirror=https://docker.mirrors.ustc.edu.cn,https://reg-mirror.qiniu.com,https://mirror.ccs.tencentyun.com --mount /var/lib/minikube:/var/lib/docker</code></p>
<p>To use the minikube dashboard, start like this:
<code>minikube start --cpus=2 --memory=2000mb \ --registry-mirror=https://docker.mirrors.ustc.edu.cn,https://reg-mirror.qiniu.com,https://mirror.ccs.tencentyun.com</code></p>
<p><em>Tell Docker CLI to talk to minikube&rsquo;s VM:</em> <code>eval $(minikube docker-env)</code></p>
<p><code>eval $(minikube docker-env)</code> can be added to your shell rc (<code>~/.zshrc</code> or <code>~/.bashrc</code>) so you don&rsquo;t type it each time.</p>
</div>
        </div>
    </div>
<h3 id="possible-issues">
    <a href="#possible-issues" class="header-anchor" aria-label="Link to Possible issues"></a>Possible issues</h3>
<div class="details admonition warning open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-exclamation-triangle fa-fw" aria-hidden="true"></i>Warning<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content"><p><em>If you start <code>minikube</code> on top of <code>Docker Desktop</code>, it reuses that VM and config. Due to resource limits, <code>minikube</code> may fail to start.</em></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-tex" data-lang="tex"><span class="line"><span class="cl">😄  minikube v1.24.0 on Darwin 12.2.1
</span></span><span class="line"><span class="cl">✨  Using the docker driver based on existing profile
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">⛔  Docker Desktop only has 1986MiB available, you may encounter application deployment failures.
</span></span><span class="line"><span class="cl">💡  Suggestion:
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    1. Click on &#34;Docker for Desktop&#34; menu icon
</span></span><span class="line"><span class="cl">    2. Click &#34;Preferences&#34;
</span></span><span class="line"><span class="cl">    3. Click &#34;Resources&#34;
</span></span><span class="line"><span class="cl">    4. Increase &#34;Memory&#34; slider bar to 2.25 GB or higher
</span></span><span class="line"><span class="cl">    5. Click &#34;Apply <span class="nb">&amp;</span> Restart&#34;
</span></span><span class="line"><span class="cl">📘  Documentation: https://docs.docker.com/docker-for-mac/#resources
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">❗  You cannot change the memory size for an existing minikube cluster. Please first delete the cluster.
</span></span><span class="line"><span class="cl">👍  Starting minikube without Kubernetes minikube in cluster minikube
</span></span></code></pre></td></tr></table>
</div>
</div><blockquote>
<p><code>minikube delete</code> <em>after adjusting docker resources, delete and recreate, then restart</em></p>
</blockquote>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-tex" data-lang="tex"><span class="line"><span class="cl">🔥  Deleting &#34;minikube&#34; in docker ...
</span></span><span class="line"><span class="cl">🔥  Removing ~/.minikube/machines/minikube ...
</span></span><span class="line"><span class="cl">💀  Removed all traces of the &#34;minikube&#34; cluster.
</span></span></code></pre></td></tr></table>
</div>
</div></div>
        </div>
    </div>
<h2 id="post-start-environment-check">
    <a href="#post-start-environment-check" class="header-anchor" aria-label="Link to Post-start environment check"></a>Post-start environment check</h2>
<div class="details admonition example open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-list-ol fa-fw" aria-hidden="true"></i>Example<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content"><blockquote>
<p>Start command: <code>minikube start --no-kubernetes --insecure-registry=https://docker.mirrors.ustc.edu.cn,https://reg-mirror.qiniu.com,https://mirror.ccs.tencentyun.com</code></p>
</blockquote>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-tex" data-lang="tex"><span class="line"><span class="cl">  minikube v1.24.0 on Darwin 10.15.7
</span></span><span class="line"><span class="cl">    ▪ MINIKUBE<span class="nb">_</span>ACTIVE<span class="nb">_</span>DOCKERD=minikube
</span></span><span class="line"><span class="cl">✨  Using the hyperkit driver based on user configuration
</span></span><span class="line"><span class="cl">👍  Starting minikube without Kubernetes minikube in cluster minikube
</span></span><span class="line"><span class="cl">🔥  Creating hyperkit VM (CPUs=2, Memory=2000MB, Disk=20480MB) ...
</span></span><span class="line"><span class="cl">🏄  Done! minikube is ready without Kubernetes!
</span></span><span class="line"><span class="cl">╭───────────────────────────────────────────────────────────────────────────────────────╮
</span></span><span class="line"><span class="cl">│                                                                                       │
</span></span><span class="line"><span class="cl">│                       💡  Things to try without Kubernetes ...                        │
</span></span><span class="line"><span class="cl">│                                                                                       │
</span></span><span class="line"><span class="cl">│    - &#34;minikube ssh&#34; to SSH into minikube&#39;s node.                                      │
</span></span><span class="line"><span class="cl">│    - &#34;minikube docker-env&#34; to point your docker-cli to the docker inside minikube.    │
</span></span><span class="line"><span class="cl">│    - &#34;minikube image&#34; to build images without docker.                                 │
</span></span><span class="line"><span class="cl">│                                                                                       │
</span></span><span class="line"><span class="cl">╰───────────────────────────────────────────────────────────────────────────────────────╯
</span></span></code></pre></td></tr></table>
</div>
</div><blockquote>
<p><code>eval $(minikube docker-env)</code> <strong>lets the Docker CLI talk to minikube&rsquo;s VM</strong></p>
</blockquote>
<div class="details admonition tip open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-lightbulb fa-fw" aria-hidden="true"></i>Tip<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content">Add this line to <code>.bash_profile</code> or <code>.zshrc</code> or &hellip; if you want to <em>use minikube&rsquo;s daemon</em> by default (or if you do not want to set this every time you open a new terminal).</div>
        </div>
    </div>
<blockquote>
<p><code>docker info</code> to see the docker info in this terminal</p>
</blockquote>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-tex" data-lang="tex"><span class="line"><span class="cl">Kernel Version: 4.19.202
</span></span><span class="line"><span class="cl"> Operating System: Buildroot 2021.02.4
</span></span><span class="line"><span class="cl"> OSType: linux
</span></span><span class="line"><span class="cl"> Architecture: x86<span class="nb">_</span>64
</span></span><span class="line"><span class="cl"> CPUs: 2
</span></span><span class="line"><span class="cl"> Total Memory: 1.894GiB
</span></span><span class="line"><span class="cl"> Name: minikube
</span></span><span class="line"><span class="cl"> ID: STNM:GBUS:PMHK:ASTU:BZHZ:WIEY:L6F3:YOMH:M432:S5XK:PAT5:IU2D
</span></span><span class="line"><span class="cl"> Docker Root Dir: /var/lib/docker
</span></span><span class="line"><span class="cl"> Debug Mode: false
</span></span><span class="line"><span class="cl"> Registry: https://index.docker.io/v1/
</span></span><span class="line"><span class="cl"> Labels:
</span></span><span class="line"><span class="cl">  provider=hyperkit
</span></span><span class="line"><span class="cl"> Experimental: false
</span></span><span class="line"><span class="cl"> Insecure Registries:
</span></span><span class="line"><span class="cl">  reg-mirror.qiniu.com
</span></span><span class="line"><span class="cl">  docker.mirrors.ustc.edu.cn
</span></span><span class="line"><span class="cl">  mirror.ccs.tencentyun.com
</span></span><span class="line"><span class="cl">  10.96.0.0/12
</span></span><span class="line"><span class="cl">  127.0.0.0/8
</span></span><span class="line"><span class="cl"> Live Restore Enabled: false
</span></span><span class="line"><span class="cl"> Product License: Community Engine
</span></span></code></pre></td></tr></table>
</div>
</div><blockquote>
<p>Open a new terminal and check <code>docker info</code> on the host (a machine that still has docker desktop installed — for comparison):</p>
</blockquote>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-tex" data-lang="tex"><span class="line"><span class="cl">Kernel Version: 5.10.76-linuxkit
</span></span><span class="line"><span class="cl">Operating System: Docker Desktop
</span></span><span class="line"><span class="cl">OSType: linux
</span></span><span class="line"><span class="cl">Architecture: x86<span class="nb">_</span>64
</span></span><span class="line"><span class="cl">CPUs: 3
</span></span><span class="line"><span class="cl">Total Memory: 4.083GiB
</span></span><span class="line"><span class="cl">Name: docker-desktop
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">HTTP Proxy: http.docker.internal:3128
</span></span><span class="line"><span class="cl"> HTTPS Proxy: http.docker.internal:3128
</span></span><span class="line"><span class="cl"> Registry: https://index.docker.io/v1/
</span></span><span class="line"><span class="cl"> Labels:
</span></span><span class="line"><span class="cl">  Experimental: false
</span></span><span class="line"><span class="cl"> Insecure Registries:
</span></span><span class="line"><span class="cl">  127.0.0.0/8
</span></span><span class="line"><span class="cl"> Registry Mirrors:
</span></span><span class="line"><span class="cl">  https://registry-1.docker.io/
</span></span><span class="line"><span class="cl">  https://hub-mirror.c.163.com/
</span></span><span class="line"><span class="cl">  https://mirror.baidubce.com/
</span></span><span class="line"><span class="cl">  https://registry.cn-hangzhou.aliyuncs.com/
</span></span><span class="line"><span class="cl">  https://docker.mirrors.ustc.edu.cn/
</span></span><span class="line"><span class="cl">  https://mirror.ccs.tencentyun.com/
</span></span><span class="line"><span class="cl">  https://registry.docker-cn.com/
</span></span><span class="line"><span class="cl">  https://reg-mirror.qiniu.com/
</span></span><span class="line"><span class="cl">  https://dockerhub.azk8s.cn/
</span></span></code></pre></td></tr></table>
</div>
</div></div>
        </div>
    </div>
<h2 id="change-image-registries">
    <a href="#change-image-registries" class="header-anchor" aria-label="Link to Change image registries"></a>Change image registries</h2>
<blockquote>
<p><strong>Don&rsquo;t make this change inside the minikube environment.</strong> Pass it at start: <code>minikube start --image-mirror-country='cn'</code> etc.; see <a href="https://minikube.sigs.k8s.io/docs/commands/start/" target="_blank" rel="noopener noreffer ">minikube start</a> or <a href="#advanced-start" rel="">Advanced start</a></p>
</blockquote>
<div class="details admonition example open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-list-ol fa-fw" aria-hidden="true"></i>Example<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content"><blockquote>
<p><code>minikube ssh</code>  connect to the minikube node</p>
<p><code>sudo mkdir -p /etc/docker</code> create the docker directory</p>
<p><code>vi /etc/docker/daemon.json</code> edit the config</p>
<p><code>daemon.json</code> <strong>daemon.json</strong> config</p>
</blockquote>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-json" data-lang="json"><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">     <span class="nt">&#34;registry-mirrors&#34;</span><span class="p">:</span> <span class="p">[</span>
</span></span><span class="line"><span class="cl">        <span class="s2">&#34;https://registry-1.docker.io&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">        <span class="s2">&#34;https://hub-mirror.c.163.com&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">        <span class="s2">&#34;https://mirror.baidubce.com&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">        <span class="s2">&#34;https://registry.cn-hangzhou.aliyuncs.com&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">        <span class="s2">&#34;http://f1361db2.m.daocloud.io&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">        <span class="s2">&#34;https://docker.mirrors.ustc.edu.cn&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">        <span class="s2">&#34;https://mirror.ccs.tencentyun.com&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">        <span class="s2">&#34;https://registry.docker-cn.com&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">        <span class="s2">&#34;https://reg-mirror.qiniu.com&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">        <span class="s2">&#34;https://dockerhub.azk8s.cn&#34;</span>
</span></span><span class="line"><span class="cl">  <span class="p">]</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></td></tr></table>
</div>
</div><blockquote>
<p><code>sudo systemctl daemon-reload</code></p>
<p><code>sudo systemctl restart docker</code></p>
</blockquote>
</div>
        </div>
    </div>
<h2 id="dashboard">
    <a href="#dashboard" class="header-anchor" aria-label="Link to Dashboard"></a>Dashboard</h2>
<p><code>minikube dashboard</code></p>
<div class="details admonition example open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-list-ol fa-fw" aria-hidden="true"></i>Example<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content"><blockquote>
<p><code>minikube start --driver=hyperkit --cpus=2 --memory=2000mb --registry-mirror=https://docker.mirrors.ustc.edu.cn,https://reg-mirror.qiniu.com,https://mirror.ccs.tencentyun.com</code></p>
<p><code>minikube dashboard</code></p>
</blockquote>
</div>
        </div>
    </div>
<h2 id="directory-mounting">
    <a href="#directory-mounting" class="header-anchor" aria-label="Link to Directory mounting"></a>Directory mounting</h2>
<blockquote>
<p>This will start the mount daemon and automatically mount files into minikube.</p>
</blockquote>
<p><code>minikube mount &lt;local directory&gt;:&lt;host directory&gt;</code></p>
<p><strong>Mapping/mount chain</strong>: <code>host volumes</code>&lt;-&gt;<code>docker desktop VM volumes</code>&lt;-&gt;<code>docker container volumes</code></p>
<h3 id="driver-default-mount-paths">
    <a href="#driver-default-mount-paths" class="header-anchor" aria-label="Link to Driver default mount paths"></a>Driver default mount paths</h3>
<p>Some hypervisors, have built-in host folder sharing. Driver mounts are reliable with good performance, but the paths are not predictable across operating systems or hypervisors:</p>
<table>
<thead>
<tr>
<th style="text-align:left">Driver</th>
<th style="text-align:left">OS</th>
<th style="text-align:left">HostFolder</th>
<th style="text-align:left">VM</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">VirtualBox</td>
<td style="text-align:left">Linux</td>
<td style="text-align:left">/home</td>
<td style="text-align:left">/hosthome</td>
</tr>
<tr>
<td style="text-align:left">VirtualBox</td>
<td style="text-align:left">macOS</td>
<td style="text-align:left">/Users</td>
<td style="text-align:left">/Users</td>
</tr>
<tr>
<td style="text-align:left">VirtualBox</td>
<td style="text-align:left">Windows</td>
<td style="text-align:left">C://Users</td>
<td style="text-align:left">/c/Users</td>
</tr>
<tr>
<td style="text-align:left">VMware Fusion</td>
<td style="text-align:left">macOS</td>
<td style="text-align:left">/Users</td>
<td style="text-align:left">/mnt/hgfs/Users</td>
</tr>
<tr>
<td style="text-align:left">KVM</td>
<td style="text-align:left">Linux</td>
<td style="text-align:left">Unsupported</td>
<td></td>
</tr>
<tr>
<td style="text-align:left">HyperKit</td>
<td style="text-align:left">Linux</td>
<td style="text-align:left">Unsupported (see NFS mounts)</td>
<td></td>
</tr>
</tbody>
</table>
<p><em>These mounts can be disabled by passing &ndash;disable-driver-mounts to minikube start.</em></p>
<h2 id="running-local-apps">
    <a href="#running-local-apps" class="header-anchor" aria-label="Link to Running local apps"></a><strong>Running local apps</strong></h2>
<blockquote>
<p>If you use directory mapping you must enable mounting, and mind the mount path — otherwise files or configs won&rsquo;t be found.</p>
</blockquote>
<h3 id="files-or-configs-not-found">
    <a href="#files-or-configs-not-found" class="header-anchor" aria-label="Link to Files or configs not found"></a><strong>Files or configs not found</strong></h3>
<div class="details admonition warning open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-exclamation-triangle fa-fw" aria-hidden="true"></i>Warning<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content"><p>Cause:</p>
<ul>
<li>With <code>docker desktop</code>, the mapping is done for you: <code>host volumes</code>&lt;-&gt;<code>docker desktop VM volumes</code>&lt;-&gt;<code>docker container volumes</code></li>
<li>When you run <code>docker run</code> or <code>docker-compose up</code> locally via <code>minikube</code>, it actually runs inside the <code>minikube vm</code>, but the <code>minikube vm</code> has <strong>no mapping of your host source code</strong></li>
</ul>
</div>
        </div>
    </div>
<h3 id="solution">
    <a href="#solution" class="header-anchor" aria-label="Link to Solution"></a><strong>Solution</strong></h3>
<blockquote>
<p><strong>Map/mount your working directory on the host</strong>:</p>
<ul>
<li><code>minikube mount $HOME/workspace:$HOME/workspace</code></li>
<li><strong>Mind the mapping path inside the minikube vm: the mount path must match the real path</strong></li>
<li><em>Watch directory permissions — mounting under your own user dir usually has no permission issues</em></li>
<li>You can mount multiple directories</li>
</ul>
</blockquote>
<div class="details admonition tip open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-lightbulb fa-fw" aria-hidden="true"></i>Tip<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content"><p>Put your source under one unified working directory for easy mounting and search, e.g.:</p>
<ul>
<li><code>$HOME/workspace</code> <strong>source workspace; can be mounted as a whole</strong></li>
<li><code>$HOME/workspace/git.company.com</code> <em>company source workspace; company code only</em></li>
<li><code>$HOME/workspace/github.com</code> <em>github source workspace</em></li>
<li><code>$HOME/workspace/gitee.com</code></li>
</ul>
</div>
        </div>
    </div>
<h2 id="start-on-boot">
    <a href="#start-on-boot" class="header-anchor" aria-label="Link to Start on boot"></a>Start on boot</h2>
<blockquote>
<p><code>--mount --mount-string=$HOME/workspace:$HOME/workspace</code> <em>may have issues; mounting via <code>minikube mount</code> after start is recommended</em></p>
</blockquote>
<h3 id="mount-only-the-current-project-directory">
    <a href="#mount-only-the-current-project-directory" class="header-anchor" aria-label="Link to Mount only the current project directory"></a><strong>Mount only the current project directory</strong></h3>
<ul>
<li>Pro: fewer mount dirs, less space</li>
<li>Con: switching projects means re-mounting — tedious</li>
</ul>
<blockquote>
<p><strong>Prefer mounting the whole working directory (mind the size) — no extra steps when switching projects</strong></p>
</blockquote>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># --mount --mount-string=$HOME/workspace:$HOME/workspace</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">#minikube delete</span>
</span></span><span class="line"><span class="cl">minikube start --no-kubernetes --driver<span class="o">=</span>hyperkit --cpus<span class="o">=</span><span class="m">2</span> --memory<span class="o">=</span>2gb --disk-size<span class="o">=</span>20gb <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>--image-mirror-country<span class="o">=</span>cn <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>--registry-mirror<span class="o">=</span>https://docker.mirrors.ustc.edu.cn,https://reg-mirror.qiniu.com,https://mirror.ccs.tencentyun.com
</span></span><span class="line"><span class="cl"><span class="nb">eval</span> <span class="k">$(</span>minikube docker-env<span class="k">)</span>
</span></span><span class="line"><span class="cl">minikube mount <span class="si">${</span><span class="nv">PWD</span><span class="si">}</span>:<span class="si">${</span><span class="nv">PWD</span><span class="si">}</span>
</span></span></code></pre></td></tr></table>
</div>
</div><h3 id="mount-the-whole-working-directory">
    <a href="#mount-the-whole-working-directory" class="header-anchor" aria-label="Link to Mount the whole working directory"></a><strong>Mount the whole working directory</strong></h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span><span class="lnt">9
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># issues here {a lone --mount will mount: /Users:/minikube-host/; --mount-string mounts only the given dir, no --mount needed then — recommended}</span>
</span></span><span class="line"><span class="cl"><span class="c1"># --mount --mount-string=$HOME/workspace:$HOME/workspace</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">#minikube delete</span>
</span></span><span class="line"><span class="cl">minikube start --no-kubernetes --driver<span class="o">=</span>hyperkit --cpus<span class="o">=</span><span class="m">2</span> --memory<span class="o">=</span>2gb --disk-size<span class="o">=</span>20gb <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>--image-mirror-country<span class="o">=</span>cn <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>--registry-mirror<span class="o">=</span>https://docker.mirrors.ustc.edu.cn,https://reg-mirror.qiniu.com,https://mirror.ccs.tencentyun.com
</span></span><span class="line"><span class="cl"><span class="nb">eval</span> <span class="k">$(</span>minikube docker-env<span class="k">)</span>
</span></span><span class="line"><span class="cl">minikube mount <span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/workspace:<span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/workspace
</span></span></code></pre></td></tr></table>
</div>
</div><h3 id="mount-the-whole-working-directory-and-run-in-the-background">
    <a href="#mount-the-whole-working-directory-and-run-in-the-background" class="header-anchor" aria-label="Link to Mount the whole working directory and run in the background"></a><em>Mount the whole working directory and run in the background</em></h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># --mount --mount-string=$HOME/workspace:$HOME/workspace</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">#minikube delete</span>
</span></span><span class="line"><span class="cl">minikube start --no-kubernetes --driver<span class="o">=</span>hyperkit --cpus<span class="o">=</span><span class="m">2</span> --memory<span class="o">=</span>2gb --disk-size<span class="o">=</span>40gb <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>--image-mirror-country<span class="o">=</span>cn <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>--registry-mirror<span class="o">=</span>https://docker.mirrors.ustc.edu.cn,https://reg-mirror.qiniu.com,https://mirror.ccs.tencentyun.com
</span></span><span class="line"><span class="cl"><span class="nb">eval</span> <span class="k">$(</span>minikube docker-env<span class="k">)</span>
</span></span><span class="line"><span class="cl">nohup minikube mount <span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/workspace:<span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/workspace <span class="p">&amp;</span>
</span></span></code></pre></td></tr></table>
</div>
</div><h2 id="caveats">
    <a href="#caveats" class="header-anchor" aria-label="Link to Caveats"></a><strong>Caveats</strong></h2>
<ul>
<li>After minikube starts, run <code>eval $(minikube docker-env)</code></li>
<li><em>Mount directories after minikube starts</em> — see <a href="#running-local-apps" rel="">Running local apps</a></li>
<li>Pass <code>--driver</code> at start; if it&rsquo;s <code>docker</code>, make sure the <code>docker daemon</code> is running</li>
<li>If the mount flag is wrong, run <code>minikube mount --kill</code> and remove the dir from the <code>minikube vm</code></li>
<li><code>minikube delete — you don't need to run it every time</code></li>
</ul>
<h2 id="more">
    <a href="#more" class="header-anchor" aria-label="Link to More"></a>More</h2>
<ul>
<li><strong><a href="https://minikube.sigs.k8s.io/docs/tutorials/docker_desktop_replacement/" target="_blank" rel="noopener noreffer ">Using minikube as Docker Desktop Replacement</a></strong></li>
<li><a href="https://minikube.sigs.k8s.io/docs/handbook/registry/" target="_blank" rel="noopener noreffer ">How to interact with registries</a></li>
<li><a href="https://minikube.sigs.k8s.io/docs/commands/image/#minikube-image-build" target="_blank" rel="noopener noreffer ">minikube-image-build</a></li>
<li><a href="https://github.com/containerd/containerd" target="_blank" rel="noopener noreffer ">containerd</a></li>
</ul>
<h2 id="references">
    <a href="#references" class="header-anchor" aria-label="Link to References"></a>References</h2>
<ul>
<li><a href="https://dhwaneetbhatt.com/blog/run-docker-without-docker-desktop-on-macos" target="_blank" rel="noopener noreffer ">run-docker-without-docker-desktop-on-macos</a></li>
<li><a href="https://minikube.sigs.k8s.io/docs/" target="_blank" rel="noopener noreffer ">minikube docs</a></li>
</ul>]]></description></item><item><title>Common Git Commands &amp; Config</title><link>https://blog.xwi88.com/en/git-common-config/</link><pubDate>Thu, 10 Mar 2022 21:31:19 +0800</pubDate><author>xwi88</author><guid>https://blog.xwi88.com/en/git-common-config/</guid><description><![CDATA[<p>Sharing the <a href="https://git-scm.com/" target="_blank" rel="noopener noreffer ">git</a> [gɪt] config I&rsquo;ve accumulated over the years. The content below is based on version <a href="https://git-scm.com/docs/git/2.34.0" target="_blank" rel="noopener noreffer "><code>2.34.1</code></a>; if anything differs, upgrade your git first!</p>
<blockquote>
<p><strong>Copyright notice</strong>: This is an original article by <strong><a href="https://github.com/xwi88" target="_blank" rel="noopener noreffer ">xwi88</a></strong>, licensed under <a href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank" rel="noopener noreffer ">CC BY-NC 4.0</a>. Commercial use is prohibited; please cite the source when reposting. Follow at <a href="https://github.com/xwi88" target="_blank" rel="noopener noreffer ">https://github.com/xwi88</a></p>
</blockquote>
<h2 id="basic-account-config">
    <a href="#basic-account-config" class="header-anchor" aria-label="Link to Basic account config"></a>Basic account config</h2>
<blockquote>
<p><code>--global</code> <em>means global config</em>; <strong>non-global config must be set inside the specific git project directory</strong></p>
</blockquote>
<ul>
<li><code>git config --global user.name [your_name]</code></li>
<li><code>git config --global user.email [your_email]</code></li>
<li><code>git config --global --list</code> <strong>view global git config</strong></li>
<li><code>git config --list</code> <em>view project git config</em></li>
</ul>
<h3 id="signed-commit-setup">
    <a href="#signed-commit-setup" class="header-anchor" aria-label="Link to Signed-commit setup"></a>Signed-commit setup</h3>
<blockquote>
<p>configure your Git client to sign commits by default for a local repository, in Git versions 2.0.0 and above</p>
</blockquote>
<ul>
<li><code>git config --global user.signingkey [KeyID]</code></li>
<li><code>git config --global commit.gpgsign true</code></li>
</ul>
<p>See also: <a href="/git-sign-tags-commits-with-gpg/" rel="">Signing Git commits/tags with GPG</a> for setup.</p>
<h2 id="credential-storage">
    <a href="#credential-storage" class="header-anchor" aria-label="Link to Credential storage"></a>Credential storage</h2>
<blockquote>
<p>To avoid typing the password every time, let the machine remember it. <em>MacOS</em> uses <strong>Keychain Access</strong> to store your password and other credentials.</p>
</blockquote>
<ul>
<li><code>git config --global credential.helper store</code> <strong>persistently save your password/credentials on this machine</strong></li>
<li><code>git config --global credential.helper 'cache --timeout=300'</code> <em>cache the password for 300s</em></li>
</ul>
<blockquote>
<p><strong>More</strong>:</p>
<ul>
<li><a href="https://git-scm.com/docs/gitcredentials" target="_blank" rel="noopener noreffer ">gitcredentials</a></li>
<li><a href="https://git-scm.com/docs/git-credential-cache" target="_blank" rel="noopener noreffer ">git-credential-cache</a></li>
</ul>
</blockquote>
<div class="details admonition warning open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-exclamation-triangle fa-fw" aria-hidden="true"></i>Warning<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content"><blockquote>
<p>If you have MFA enabled, you must use a <strong>Personal Token</strong> instead of the password.</p>
<ul>
<li>github path: <a href="https://github.com/settings/tokens" target="_blank" rel="noopener noreffer ">Settings Developer settings</a>-&gt;<strong>Personal access tokens</strong>-&gt;<em>Generate new token</em></li>
</ul>
</blockquote>
<p><strong>Personal access tokens</strong> 📢</p>
<ul>
<li><strong>Visible only when generated — save it carefully</strong></li>
<li><strong>Mind the scopes and expiration</strong></li>
</ul>
</div>
        </div>
    </div>
<h2 id="credential-cleanup">
    <a href="#credential-cleanup" class="header-anchor" aria-label="Link to Credential cleanup"></a>Credential cleanup</h2>
<blockquote>
<p>After a password changes or expires, clear the stored one, or you may get <code>login failed</code> / <code>no permission</code> errors.</p>
</blockquote>
<ul>
<li><code>git config --system --unset credential.helper</code></li>
<li><code>git config --global credential.helper 'cache --timeout=5'</code> <em>or set a very short expiry to flush the cached password</em></li>
<li><code>git config --global credential.helper store</code> <strong>re-enable credential storage</strong></li>
</ul>
<h2 id="prettier-log-output">
    <a href="#prettier-log-output" class="header-anchor" aria-label="Link to Prettier log output"></a>Prettier log output</h2>
<blockquote>
<p>The plain <a href="https://git-scm.com/docs/git-log" target="_blank" rel="noopener noreffer "><code>git log</code></a> is too bare to inspect details. We can format it, and <code>git alias</code> makes it easy to define our own <em>git log</em> command — <strong>do not override git&rsquo;s built-in commands</strong>.</p>
</blockquote>
<div class="details admonition tip open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-lightbulb fa-fw" aria-hidden="true"></i>Tip<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content"><p>My usual <em>git log</em> config:</p>
<blockquote>
<p><code>git config --global alias.lg &quot;log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&lt;%an&gt;%Creset | %C(red)%cs%Creset' --abbrev-commit&quot;</code></p>
</blockquote>
<p><code>git lg -4</code></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">* 16074ef - <span class="o">(</span>HEAD -&gt; main, origin/main<span class="o">)</span> update posts git-sign-tag-commit-with-gpg <span class="o">(</span><span class="m">2</span> hours ago<span class="o">)</span> &lt;xwi88&gt; <span class="p">|</span> 2022-03-10
</span></span><span class="line"><span class="cl">* e39e092 - support l2d widget <span class="o">(</span><span class="m">23</span> hours ago<span class="o">)</span> &lt;xwi88&gt; <span class="p">|</span> 2022-03-10
</span></span><span class="line"><span class="cl">* 11605af - close cookie tip and update posts <span class="o">(</span><span class="m">24</span> hours ago<span class="o">)</span> &lt;xwi88&gt; <span class="p">|</span> 2022-03-09
</span></span><span class="line"><span class="cl">* 9b548b6 - update posts git sign with gpg <span class="o">(</span><span class="m">25</span> hours ago<span class="o">)</span> &lt;xwi88&gt; <span class="p">|</span> 2022-03-09
</span></span></code></pre></td></tr></table>
</div>
</div><p>To also show <strong>gpg</strong> signature info:</p>
<blockquote>
<p><code>git config --global alias.lsg &quot;log --color --graph --pretty=format:'%C(cyan)%G?%Creset %Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&lt;%an&gt;%Creset | %C(red)%cs%Creset' --abbrev-commit&quot;</code></p>
</blockquote>
<p><code>git lsg -4</code></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">* G 16074ef - <span class="o">(</span>HEAD -&gt; main, origin/main<span class="o">)</span> update posts git-sign-tag-commit-with-gpg <span class="o">(</span><span class="m">2</span> hours ago<span class="o">)</span> &lt;xwi88&gt; <span class="p">|</span> 2022-03-10
</span></span><span class="line"><span class="cl">* G e39e092 - support l2d widget <span class="o">(</span><span class="m">23</span> hours ago<span class="o">)</span> &lt;xwi88&gt; <span class="p">|</span> 2022-03-10
</span></span><span class="line"><span class="cl">* G 11605af - close cookie tip and update posts <span class="o">(</span><span class="m">24</span> hours ago<span class="o">)</span> &lt;xwi88&gt; <span class="p">|</span> 2022-03-09
</span></span><span class="line"><span class="cl">* G 9b548b6 - update posts git sign with gpg <span class="o">(</span><span class="m">25</span> hours ago<span class="o">)</span> &lt;xwi88&gt; <span class="p">|</span> 2022-03-09
</span></span></code></pre></td></tr></table>
</div>
</div><p>For even more detail:</p>
<blockquote>
<p><code>git config --global alias.llsg &quot;log --color --graph --pretty=format:'%C(cyan)%G?%Creset %Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&lt;%an&gt;%Creset | %C(red)%cs%Creset [%GK trust:%GT] %C(yellow)%GS%Creset' --abbrev-commit&quot;</code></p>
</blockquote>
<p><code>git llsg -4</code></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">* G 16074ef - <span class="o">(</span>HEAD -&gt; main, origin/main<span class="o">)</span> update posts git-sign-tag-commit-with-gpg <span class="o">(</span><span class="m">2</span> hours ago<span class="o">)</span> &lt;xwi88&gt; <span class="p">|</span> 2022-03-10 <span class="o">[</span>C739E6A64E102CD0 trust:ultimate<span class="o">]</span> xwi88 &lt;278810732@qq.com&gt;
</span></span><span class="line"><span class="cl">* G e39e092 - support l2d widget <span class="o">(</span><span class="m">23</span> hours ago<span class="o">)</span> &lt;xwi88&gt; <span class="p">|</span> 2022-03-10 <span class="o">[</span>90684042688CB9BE trust:ultimate<span class="o">]</span> xwi88 &lt;278810732@qq.com&gt;
</span></span><span class="line"><span class="cl">* G 11605af - close cookie tip and update posts <span class="o">(</span><span class="m">24</span> hours ago<span class="o">)</span> &lt;xwi88&gt; <span class="p">|</span> 2022-03-09 <span class="o">[</span>90684042688CB9BE trust:ultimate<span class="o">]</span> xwi88 &lt;278810732@qq.com&gt;
</span></span><span class="line"><span class="cl">* G 9b548b6 - update posts git sign with gpg <span class="o">(</span><span class="m">25</span> hours ago<span class="o">)</span> &lt;xwi88&gt; <span class="p">|</span> 2022-03-09 <span class="o">[</span>90684042688CB9BE trust:ultimate<span class="o">]</span> xwi88 &lt;278810732@qq.com&gt;
</span></span></code></pre></td></tr></table>
</div>
</div></div>
        </div>
    </div>
<div class="details admonition warning open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-exclamation-triangle fa-fw" aria-hidden="true"></i>Warning<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content"><ul>
<li><strong>Always pass a log entry count</strong></li>
<li><strong>Don&rsquo;t make the format too complex — output may slow down</strong></li>
<li><strong>If you use <code>gpg signing</code>, make sure you don&rsquo;t have too many <code>gpg key</code>s</strong></li>
</ul>
</div>
        </div>
    </div>
<h2 id="basic-commands">
    <a href="#basic-commands" class="header-anchor" aria-label="Link to Basic commands"></a>Basic commands</h2>
<blockquote>
<p>For more detail on any command, run <code>git &lt;command&gt; --help</code></p>
</blockquote>
<ul>
<li><code>git add [&lt;path_spec&gt;...]</code> <strong>stage files into the <code>Index</code></strong>
<ul>
<li><code>git add [&lt;path_spec&gt;...] -n</code> <strong>dry-run: show what would happen, without doing it</strong></li>
</ul>
</li>
<li><code>git status -s</code> show the current branch status — files differ between working tree and index: <code>modified</code>, <code>not staged</code>, <code>staged but not committed</code></li>
<li><code>git diff</code>
<ul>
<li><code>git diff [&lt;path&gt;...]</code> diff working tree vs index</li>
<li><code>git diff &lt;commit&gt;...&lt;commit&gt; [&lt;path&gt;...]</code> diff between commits</li>
<li><code>git diff --cached [&lt;commit&gt;] [&lt;path&gt;...]</code> diff index vs repository</li>
</ul>
</li>
<li><code>git commit</code> commit staged changes to the local repo
<ul>
<li><code>git commit -m &lt;message&gt;</code> commit to local repo</li>
<li><code>git commit -S -m &lt;message&gt;</code> <strong>sign</strong> and commit; requires your <strong>GPG key</strong></li>
<li><code>git commit -a -m</code> stage and commit all changes, skipping <code>git add</code>; generally avoid this</li>
<li><code>git commit --amend</code> redo the latest commit — to <strong>edit its message</strong> or append changes; <strong>don&rsquo;t chain this</strong>, and <strong>avoid it for already-pushed commits</strong></li>
</ul>
</li>
<li><code>git reset</code> undo changes; see <a href="#checkout-vs-reset" rel="">checkout vs reset</a></li>
<li><code>git rm</code> remove files from the index and working tree</li>
<li><code>git mv &lt;old&gt; &lt;new&gt;</code> <em>file rename</em>; equivalent to <code>mv old new</code>, <code>git add</code> the new file and <code>git rm</code> the old</li>
</ul>
<h2 id="branch-operations">
    <a href="#branch-operations" class="header-anchor" aria-label="Link to Branch operations"></a>Branch operations</h2>
<h3 id="remote-branch-config">
    <a href="#remote-branch-config" class="header-anchor" aria-label="Link to Remote branch config"></a>Remote branch config</h3>
<ul>
<li><code>git remote -v</code></li>
<li><code>git remote add &lt;name&gt; &lt;url&gt;</code> add a remote</li>
<li><code>git remote rename &lt;old&gt; &lt;new&gt;</code> rename a remote</li>
<li><code>git remote set-url &lt;name&gt; &lt;new_url&gt;</code> change a remote URL</li>
</ul>
<h3 id="cloning">
    <a href="#cloning" class="header-anchor" aria-label="Link to Cloning"></a>Cloning</h3>
<ul>
<li><code>git clone -b branch_name --single-branch &lt;url&gt;</code> single-branch clone</li>
<li><code>git clone &lt;url&gt; [dir]</code></li>
</ul>
<h3 id="fetch--sync">
    <a href="#fetch--sync" class="header-anchor" aria-label="Link to Fetch &amp; sync"></a>Fetch &amp; sync</h3>
<ul>
<li><code>git fetch --all</code> || <code>git merge</code> only fetch into the <strong>local remote-tracking branch</strong> (e.g. <code>origin/main</code>, <code>upstream/main</code>); merge into the local branch later when needed</li>
<li><code>git pull</code> fetch and merge the remote branch into the current branch; generally avoid unless you understand the consequences</li>
<li><code>git push -u &lt;repo_name&gt; &lt;branch_name&gt;</code> set up tracking between a new local branch and a remote branch — <strong>typically for a new branch&rsquo;s first push</strong></li>
</ul>
<h3 id="checkout-vs-reset">
    <a href="#checkout-vs-reset" class="header-anchor" aria-label="Link to checkout vs reset"></a>checkout vs reset</h3>
<ul>
<li><code>git checkout</code></li>
<li><code>git reset</code></li>
<li><code>git revert</code> <strong>rarely used on the CLI</strong></li>
</ul>
<table>
<thead>
<tr>
<th style="text-align:left">Git Command</th>
<th style="text-align:left">Scope</th>
<th style="text-align:left">Common use cases</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">reset</td>
<td style="text-align:left">Commit</td>
<td style="text-align:left">Discard commits in a private branch or throw away uncommited changes</td>
</tr>
<tr>
<td style="text-align:left">reset</td>
<td style="text-align:left">File</td>
<td style="text-align:left">Unstage a file</td>
</tr>
<tr>
<td style="text-align:left">checkout</td>
<td style="text-align:left">Commit</td>
<td style="text-align:left">Switch between branches or inspect old snapshots</td>
</tr>
<tr>
<td style="text-align:left">checkout</td>
<td style="text-align:left">File</td>
<td style="text-align:left">Discard changes in the working directory</td>
</tr>
<tr>
<td style="text-align:left">revert</td>
<td style="text-align:left">Commit</td>
<td style="text-align:left">Undo commits in a public branch</td>
</tr>
<tr>
<td style="text-align:left">revert</td>
<td style="text-align:left">File</td>
<td style="text-align:left">(N/A)</td>
</tr>
</tbody>
</table>
<div class="details admonition info open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-info-circle fa-fw" aria-hidden="true"></i>Info<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content"><blockquote>
<p><code>--soft</code> The staged snapshot and working directory are not altered in any way.</p>
<p><code>--mixed</code> The staged snapshot is updated to match the specified commit, but the working directory is not affected. This is the default option.</p>
<p><code>--hard</code> The staged snapshot and the working directory are both updated to match the specified commit.</p>
</blockquote>
</div>
        </div>
    </div>
<h3 id="merging--committing">
    <a href="#merging--committing" class="header-anchor" aria-label="Link to Merging &amp; committing"></a>Merging &amp; committing</h3>
<blockquote>
<p>For multi-person or large-team collaboration, master and use <code>git rebase</code>, and keep each branch&rsquo;s commit count vs the <strong>base</strong> branch <strong>minimal</strong> — easier rebases and conflict resolution for everyone.</p>
<p>If you&rsquo;ve opened a <code>PR</code>/<code>MR</code>, before <strong>reviewers</strong> review, make sure your branch is <code>Fast-Forward</code> vs the <strong>base</strong>; do not <strong>Rebase</strong> from the web UI.</p>
</blockquote>
<ul>
<li><code>git rebase</code> <strong>use with care</strong> <a href="https://mp.weixin.qq.com/s?__biz=MzIzODY3NjQ0OA==&amp;mid=2247483733&amp;idx=1&amp;sn=5adc1d9d1a241ffc3565c47d7f924125&amp;chksm=e934f1dade4378cc630dca0d1655db42418e983e08e9e6779d2f0895189ec85ae45f4751bae0&amp;token=281138563&amp;lang=zh_CN#rd" target="_blank" rel="noopener noreffer ">demo</a></li>
<li><code>git merge</code> <del><strong>not recommended</strong></del></li>
</ul>
<h3 id="branch-push--delete">
    <a href="#branch-push--delete" class="header-anchor" aria-label="Link to Branch push &amp; delete"></a>Branch push &amp; delete</h3>
<ul>
<li><code>git push</code> push the current branch; requires tracking a remote branch; for the first push use <code>git push -u &lt;name&gt; &lt;branch&gt;</code></li>
<li><code>git push -f</code> force-push the current branch to its remote</li>
<li><code>git push -f &lt;name&gt; :&lt;remote_branch&gt;</code> push an empty branch to the remote — i.e. <strong>delete the remote branch</strong></li>
<li><code>git branch -d</code> delete a local branch</li>
</ul>
<h2 id="unset-config">
    <a href="#unset-config" class="header-anchor" aria-label="Link to Unset config"></a>Unset config</h2>
<blockquote>
<p><strong>Remove the line matching the key from config file.</strong></p>
</blockquote>
<ul>
<li><code>git config --global --unset [key]</code> remove from global config</li>
<li><code>git config --unset [key]</code> remove from project config</li>
</ul>
<div class="details admonition example open">
        <div class="details-summary admonition-title">
            <i class="icon fas fa-list-ol fa-fw" aria-hidden="true"></i>Example<i class="details-icon fas fa-angle-right fa-fw" aria-hidden="true"></i>
        </div>
        <div class="details-content">
            <div class="admonition-content"><p><em>Remove a mistakenly-created entry from global config</em></p>
<p><code>git config --global --unset alias.llg</code></p>
</div>
        </div>
    </div>
<h2 id="edit-config-files">
    <a href="#edit-config-files" class="header-anchor" aria-label="Link to Edit config files"></a>Edit config files</h2>
<ul>
<li><code>git config --global -e</code> edit the global config file at <code>~/.gitconfig</code></li>
<li><code>git config -e</code> edit the project config file at <code>.git/config</code></li>
</ul>
<h2 id="references">
    <a href="#references" class="header-anchor" aria-label="Link to References"></a>References</h2>
<ul>
<li><a href="https://git-scm.com/docs" target="_blank" rel="noopener noreffer ">git docs</a></li>
<li><a href="https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases" target="_blank" rel="noopener noreffer ">Git-Basics-Git-Aliases</a></li>
<li><a href="https://git-scm.com/book/en/v2/Appendix-C:-Git-Commands-Basic-Snapshotting" target="_blank" rel="noopener noreffer ">Git-Commands-Basic-Snapshotting</a></li>
<li><a href="/git-sign-tags-commits-with-gpg/" rel="">Signing Git commits/tags with GPG</a></li>
</ul>]]></description></item></channel></rss>