summaryrefslogtreecommitdiff
path: root/devdocs/docker/engine%2Finstall%2Fcentos%2Findex.html
blob: 1a70363a0f4bd16ec1eeffa206aedda9c78b1fe7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<h1>Install Docker Engine on CentOS</h1>

<p>To get started with Docker Engine on CentOS, make sure you <a href="#prerequisites">meet the prerequisites</a>, then <a href="#installation-methods">install Docker</a>.</p> <h2 id="prerequisites">Prerequisites</h2> <h3 id="os-requirements">OS requirements</h3> <p>To install Docker Engine, you need a maintained version of CentOS 7, CentOS 8 (stream), or CentOS 9 (stream). Archived versions aren’t supported or tested.</p> <p>The <code class="language-plaintext highlighter-rouge">centos-extras</code> repository must be enabled. This repository is enabled by default, but if you have disabled it, you need to <a href="https://wiki.centos.org/AdditionalResources/Repositories" target="_blank" rel="noopener" class="_">re-enable it</a>.</p> <p>The <code class="language-plaintext highlighter-rouge">overlay2</code> storage driver is recommended.</p> <h3 id="uninstall-old-versions">Uninstall old versions</h3> <p>Older versions of Docker were called <code class="language-plaintext highlighter-rouge">docker</code> or <code class="language-plaintext highlighter-rouge">docker-engine</code>. If these are installed, uninstall them, along with associated dependencies.</p> <div class="highlight"><pre class="highlight" data-language="">$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
</pre></div> <p>It’s OK if <code class="language-plaintext highlighter-rouge">yum</code> reports that none of these packages are installed.</p> <p>The contents of <code class="language-plaintext highlighter-rouge">/var/lib/docker/</code>, including images, containers, volumes, and networks, are preserved. The Docker Engine package is now called <code class="language-plaintext highlighter-rouge">docker-ce</code>.</p> <h2 id="installation-methods">Installation methods</h2> <p>You can install Docker Engine in different ways, depending on your needs:</p> <ul> <li> <p>Most users <a href="#install-using-the-repository">set up Docker’s repositories</a> and install from them, for ease of installation and upgrade tasks. This is the recommended approach.</p> </li> <li> <p>Some users download the RPM package and <a href="#install-from-a-package">install it manually</a> and manage upgrades completely manually. This is useful in situations such as installing Docker on air-gapped systems with no access to the internet.</p> </li> <li> <p>In testing and development environments, some users choose to use automated <a href="#install-using-the-convenience-script">convenience scripts</a> to install Docker.</p> </li> </ul> <h3 id="install-using-the-repository">Install using the repository</h3> <p>Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.</p> <h4 id="set-up-the-repository">Set up the repository</h4> <p>Install the <code class="language-plaintext highlighter-rouge">yum-utils</code> package (which provides the <code class="language-plaintext highlighter-rouge">yum-config-manager</code> utility) and set up the repository.</p> <div class="highlight"><pre class="highlight" data-language="">$ sudo yum install -y yum-utils

$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
</pre></div> <h4 id="install-docker-engine">Install Docker Engine</h4> <ol> <li> <p>Install the <em>latest version</em> of Docker Engine, containerd, and Docker Compose or go to the next step to install a specific version:</p> <div class="highlight"><pre class="highlight" data-language="">$ sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
</pre></div>  <p>If prompted to accept the GPG key, verify that the fingerprint matches <code class="language-plaintext highlighter-rouge">060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35</code>, and if so, accept it.</p> <p>This command installs Docker, but it doesn’t start Docker. It also creates a <code class="language-plaintext highlighter-rouge">docker</code> group, however, it doesn’t add any users to the group by default.</p> </li> <li> <p>To install a <em>specific version</em> of Docker Engine, list the available versions in the repo, then select and install:</p> <p>a. List and sort the versions available in your repo. This example sorts results by version number, highest to lowest, and is truncated:</p> <div class="highlight"><pre class="highlight" data-language="">$ yum list docker-ce --showduplicates | sort -r

docker-ce.x86_64  3:18.09.1-3.el7                     docker-ce-stable
docker-ce.x86_64  3:18.09.0-3.el7                     docker-ce-stable
docker-ce.x86_64  18.06.1.ce-3.el7                    docker-ce-stable
docker-ce.x86_64  18.06.0.ce-3.el7                    docker-ce-stable
</pre></div>  <p>The list returned depends on which repositories are enabled, and is specific to your version of CentOS (indicated by the <code class="language-plaintext highlighter-rouge">.el7</code> suffix in this example).</p> <p>b. Install a specific version by its fully qualified package name, which is the package name (<code class="language-plaintext highlighter-rouge">docker-ce</code>) plus the version string (2nd column) starting at the first colon (<code class="language-plaintext highlighter-rouge">:</code>), up to the first hyphen, separated by a hyphen (<code class="language-plaintext highlighter-rouge">-</code>). For example, <code class="language-plaintext highlighter-rouge">docker-ce-18.09.1</code>.</p> <div class="highlight"><pre class="highlight" data-language="">$ sudo yum install docker-ce-&lt;VERSION_STRING&gt; docker-ce-cli-&lt;VERSION_STRING&gt; containerd.io docker-compose-plugin
</pre></div>  <p>This command installs Docker, but it doesn’t start Docker. It also creates a <code class="language-plaintext highlighter-rouge">docker</code> group, however, it doesn’t add any users to the group by default.</p> </li> <li> <p>Start Docker.</p> <div class="highlight"><pre class="highlight" data-language="">$ sudo systemctl start docker
</pre></div>  </li> <li> <p>Verify that Docker Engine is installed correctly by running the <code class="language-plaintext highlighter-rouge">hello-world</code> image.</p> <div class="highlight"><pre class="highlight" data-language="">$ sudo docker run hello-world
</pre></div>  <p>This command downloads a test image and runs it in a container. When the container runs, it prints a message and exits.</p> </li> </ol> <p>This installs and runs Docker Engine. Use <code class="language-plaintext highlighter-rouge">sudo</code> to run Docker commands. Continue to <a href="../linux-postinstall/index">Linux postinstall</a> to allow non-privileged users to run Docker commands and for other optional configuration steps.</p> <h4 id="upgrade-docker-engine">Upgrade Docker Engine</h4> <p>To upgrade Docker Engine, follow the <a href="#install-using-the-repository">installation instructions</a>, choosing the new version you want to install.</p> <h3 id="install-from-a-package">Install from a package</h3> <p>If you cannot use Docker’s repository to install Docker, you can download the <code class="language-plaintext highlighter-rouge">.rpm</code> file for your release and install it manually. You need to download a new file each time you want to upgrade Docker Engine.</p> <ol> <li> <p>Go to <a href="https://download.docker.com/linux/centos/" target="_blank" rel="noopener" class="_">https://download.docker.com/linux/centos/</a> and choose your version of CentOS. Then browse to <code class="language-plaintext highlighter-rouge">x86_64/stable/Packages/</code> and download the <code class="language-plaintext highlighter-rouge">.rpm</code> file for the Docker version you want to install.</p> </li> <li> <p>Install Docker Engine, changing the path below to the path where you downloaded the Docker package.</p> <div class="highlight"><pre class="highlight" data-language="">$ sudo yum install /path/to/package.rpm
</pre></div>  <p>Docker is installed but not started. The <code class="language-plaintext highlighter-rouge">docker</code> group is created, but no users are added to the group.</p> </li> <li> <p>Start Docker.</p> <div class="highlight"><pre class="highlight" data-language="">$ sudo systemctl start docker
</pre></div>  </li> <li> <p>Verify that Docker Engine is installed correctly by running the <code class="language-plaintext highlighter-rouge">hello-world</code> image.</p> <div class="highlight"><pre class="highlight" data-language="">$ sudo docker run hello-world
</pre></div>  <p>This command downloads a test image and runs it in a container. When the container runs, it prints a message and exits.</p> </li> </ol> <p>This installs and runs Docker Engine. Use <code class="language-plaintext highlighter-rouge">sudo</code> to run Docker commands. Continue to <a href="../linux-postinstall/index">Post-installation steps for Linux</a> to allow non-privileged users to run Docker commands and for other optional configuration steps.</p> <h4 id="upgrade-docker-engine-1">Upgrade Docker Engine</h4> <p>To upgrade Docker Engine, download the newer package file and repeat the <a href="#install-from-a-package">installation procedure</a>, using <code class="language-plaintext highlighter-rouge">yum -y upgrade</code> instead of <code class="language-plaintext highlighter-rouge">yum -y install</code>, and point to the new file.</p>  <h3 id="install-using-the-convenience-script">Install using the convenience script</h3> <p>Docker provides a convenience script at <a href="https://get.docker.com/">get.docker.com</a> to install Docker into development environments quickly and non-interactively. The convenience script is not recommended for production environments, but can be used as an example to create a provisioning script that is tailored to your needs. Also refer to the <a href="#install-using-the-repository">install using the repository</a> steps to learn about installation steps to install using the package repository. The source code for the script is open source, and can be found in the <a href="https://github.com/docker/docker-install" target="_blank" rel="noopener" class="_"><code class="language-plaintext highlighter-rouge">docker-install</code> repository on GitHub</a>.</p> <p class="warning">Always examine scripts downloaded from the internet before running them locally. Before installing, make yourself familiar with potential risks and limitations of the convenience script:</p> <ul> <li>The script requires <code class="language-plaintext highlighter-rouge">root</code> or <code class="language-plaintext highlighter-rouge">sudo</code> privileges to run.</li> <li>The script attempts to detect your Linux distribution and version and configure your package management system for you, and does not allow you to customize most installation parameters.</li> <li>The script installs dependencies and recommendations without asking for confirmation. This may install a large number of packages, depending on the current configuration of your host machine.</li> <li>By default, the script installs the latest stable release of Docker, containerd, and runc. When using this script to provision a machine, this may result in unexpected major version upgrades of Docker. Always test (major) upgrades in a test environment before deploying to your production systems.</li> <li>The script is not designed to upgrade an existing Docker installation. When using the script to update an existing installation, dependencies may not be updated to the expected version, causing outdated versions to be used.</li> </ul> <blockquote> <p>Tip: preview script steps before running</p> <p>You can run the script with the <code class="language-plaintext highlighter-rouge">DRY_RUN=1</code> option to learn what steps the script will execute during installation:</p> <div class="highlight"><pre class="highlight" data-language="">$ curl -fsSL https://get.docker.com -o get-docker.sh
$ DRY_RUN=1 sh ./get-docker.sh
</pre></div>  </blockquote> <p>This example downloads the script from <a href="https://get.docker.com/">get.docker.com</a> and runs it to install the latest stable release of Docker on Linux:</p> <div class="highlight"><pre class="highlight" data-language="">$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
Executing docker install script, commit: 7cae5f8b0decc17d6571f9f52eb840fbc13b2737
&lt;...&gt;
</pre></div> <p>Docker is installed. The <code class="language-plaintext highlighter-rouge">docker</code> service starts automatically on Debian based distributions. On <code class="language-plaintext highlighter-rouge">RPM</code> based distributions, such as CentOS, Fedora, RHEL or SLES, you need to start it manually using the appropriate <code class="language-plaintext highlighter-rouge">systemctl</code> or <code class="language-plaintext highlighter-rouge">service</code> command. As the message indicates, non-root users cannot run Docker commands by default.</p> <blockquote> <p><strong>Use Docker as a non-privileged user, or install in rootless mode?</strong></p> <p>The installation script requires <code class="language-plaintext highlighter-rouge">root</code> or <code class="language-plaintext highlighter-rouge">sudo</code> privileges to install and use Docker. If you want to grant non-root users access to Docker, refer to the <a href="../linux-postinstall/index#manage-docker-as-a-non-root-user">post-installation steps for Linux</a>. Docker can also be installed without <code class="language-plaintext highlighter-rouge">root</code> privileges, or configured to run in rootless mode. For instructions on running Docker in rootless mode, refer to <a href="../../security/rootless/index">run the Docker daemon as a non-root user (rootless mode)</a>.</p> </blockquote> <h4 id="install-pre-releases">Install pre-releases</h4> <p>Docker also provides a convenience script at <a href="https://test.docker.com/">test.docker.com</a> to install pre-releases of Docker on Linux. This script is equivalent to the script at <code class="language-plaintext highlighter-rouge">get.docker.com</code>, but configures your package manager to enable the “test” channel from our package repository, which includes both stable and pre-releases (beta versions, release-candidates) of Docker. Use this script to get early access to new releases, and to evaluate them in a testing environment before they are released as stable.</p> <p>To install the latest version of Docker on Linux from the “test” channel, run:</p> <div class="highlight"><pre class="highlight" data-language="">$ curl -fsSL https://test.docker.com -o test-docker.sh
$ sudo sh test-docker.sh
&lt;...&gt;
</pre></div> <h4 id="upgrade-docker-after-using-the-convenience-script">Upgrade Docker after using the convenience script</h4> <p>If you installed Docker using the convenience script, you should upgrade Docker using your package manager directly. There is no advantage to re-running the convenience script, and it can cause issues if it attempts to re-add repositories which have already been added to the host machine.</p> <h2 id="uninstall-docker-engine">Uninstall Docker Engine</h2> <ol> <li> <p>Uninstall the Docker Engine, CLI, Containerd, and Docker Compose packages:</p> <div class="highlight"><pre class="highlight" data-language="">$ sudo yum remove docker-ce docker-ce-cli containerd.io docker-compose-plugin
</pre></div>  </li> <li> <p>Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:</p> <div class="highlight"><pre class="highlight" data-language="">$ sudo rm -rf /var/lib/docker
$ sudo rm -rf /var/lib/containerd
</pre></div>  </li> </ol> <p>You must delete any edited configuration files manually.</p> <h2 id="next-steps">Next steps</h2> <ul> <li>Continue to <a href="../linux-postinstall/index">Post-installation steps for Linux</a>.</li> <li>Review the topics in <a href="https://docs.docker.com/develop/">Develop with Docker</a> to learn how to build new applications using Docker.</li> </ul> 
<p><a href="https://docs.docker.com/search/?q=requirements">requirements</a>, <a href="https://docs.docker.com/search/?q=apt">apt</a>, <a href="https://docs.docker.com/search/?q=installation">installation</a>, <a href="https://docs.docker.com/search/?q=centos">centos</a>, <a href="https://docs.docker.com/search/?q=rpm">rpm</a>, <a href="https://docs.docker.com/search/?q=install">install</a>, <a href="https://docs.docker.com/search/?q=uninstall">uninstall</a>, <a href="https://docs.docker.com/search/?q=upgrade">upgrade</a>, <a href="https://docs.docker.com/search/?q=update">update</a></p>
<div class="_attribution">
  <p class="_attribution-p">
    &copy; 2019 Docker, Inc.<br>Licensed under the Apache License, Version 2.0.<br>Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries.<br>Docker, Inc. and other parties may also have trademark rights in other terms used herein.<br>
    <a href="https://docs.docker.com/engine/install/centos/" class="_attribution-link">https://docs.docker.com/engine/install/centos/</a>
  </p>
</div>