GVKun编程网logo

一行命令安装 docker 和 docker-compose (CentOS7)(一键命令安装docker脚本)

9

以上就是给各位分享一行命令安装docker和docker-compose(CentOS7),其中也会对一键命令安装docker脚本进行解释,同时本文还将给你拓展CentOS7安装Docker和Dock

以上就是给各位分享一行命令安装 docker 和 docker-compose (CentOS7),其中也会对一键命令安装docker脚本进行解释,同时本文还将给你拓展CentOS 7 安装 Docker 和 Docker-Compose、CentOS 7 系统 安装docker及docker compose 组件、CentOS 8.0 64位安装Docker 以及 Docker Compose、centos 上安装docker和docker-compose等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

一行命令安装 docker 和 docker-compose (CentOS7)(一键命令安装docker脚本)

一行命令安装 docker 和 docker-compose (CentOS7)(一键命令安装docker脚本)

想快速装好 docker 和 docker-compose ?那就随本文用一次复制粘贴来完成安装:

环境信息

  1. 操作系统:CentOS Linux release 7.7.1908
  2. 操作账号:root
  3. Docker 版本:当前最新版本:19.03.2
  4. docker-compose 版本:当前最新版本:1.24.1

安装

执行以下命令 (若非 root 账号,请自行添加 sudo):

yum install -y yum-utils device-mapper-persistent-data lvm2 \
&& yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo \
&& yum install  -y docker-ce docker-ce-cli containerd.io \
&& systemctl start docker \
&& yum -y install epel-release \
&& yum -y install python-pip \
&& pip install --upgrade pip \
&& pip install docker-compose

等待几分钟,即完成 docker 和 docker-compose 的安装

验证

  1. docker 版本:
[root@centos7 ~]# docker version
Client: Docker Engine - Community
 Version:           19.03.2
 API version:       1.40
 Go version:        go1.12.8
 Git commit:        6a30dfc
 Built:             Thu Aug 29 05:28:55 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.2
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.8
  Git commit:       6a30dfc
  Built:            Thu Aug 29 05:27:34 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.6
  GitCommit:        894b81a4b802e4eb2a91d1ce216b8817763c29fb
 runc:
  Version:          1.0.0-rc8
  GitCommit:        425e105d5a03fabd737a126ad93d62a9eeede87f
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
  1. docker-compose 版本:
[root@centos7 ~]# docker-compose version
docker-compose version 1.24.1, build 4667896
docker-py version: 3.7.3
CPython version: 2.7.5
OpenSSL version: OpenSSL 1.0.2k-fips  26 Jan 2017
  1. 运行 hello world:
[root@centos7 ~]# docker run --rm hello-world
Unable to find image ''hello-world:latest'' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:b8ba256769a0ac28dd126d584e0a2011cd2877f3f76e093a7ae560f2a5301c00
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

操作完成,希望这一次复制粘贴能助您快速开启 docker 之旅。

本文分享 CSDN - 程序员欣宸。
如有侵权,请联系 support@oschina.cn 删除。
本文参与 “OSC 源创计划”,欢迎正在阅读的你也加入,一起分享。

CentOS 7 安装 Docker 和 Docker-Compose

CentOS 7 安装 Docker 和 Docker-Compose

环境检查

进入 root

以下所有操作都是以 root 用户执行
sudo -i

查看 Linux 发行版本

[root@localhost ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

查看内核版本

Docker 要求 CentOS 系统的内核版本高于 3.10

[root@localhost /]# uname -r
3.10.0-123.el7.x86_64

结论

发行版本为 CentOS 7,满足 Docker 环境需求,接下来用 yum 安装 docker-ce。

注意:

3.10 版本的内核,可能无法正常运行 18.06.x 及以上版本的 docker(解决方法:升级内核或者降低 docker 版本),可能报下面的错误:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "process_linux.go:293: copying bootstrap data to pipe caused "write init-p: broken pipe"": unknown.

安装 Docker

 
# 更新到最新 yum 包
yum update -y

# 卸载旧版本(如果安装过旧版本的话)
yum remove docker docker-common docker-selinux docker-engine docer-io

# 安装需要的软件包
# yum-util 提供 yum-config-manager 功能, 另外两个是 devicemapper 驱动依赖
yum install -y yum-utils device-mapper-persistent-data lvm2

# 设置 yum 源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

# 查看所有仓库中所有 docker 版本,并选择特定版本安装
yum list docker-ce --showduplicates | sort -r

* updates: centos.ustc.edu.cn
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror, langpacks

* extras: centos.ustc.edu.cn
docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable
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.3.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.2.ce-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
docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable

* base: centos.ustc.edu.cn
Available Packages

# 由于 repo 中默认只开启 stable 的仓库,故这里安装的是最新稳定版(18.09.2)
# 由于内核是 3.10 无法正常运行 18.06.x 及以上版本的 docker,所以不这么安装
# yum install -y docker-ce

# 经过测试发现,3.10 内核可以运行 18.03.1.ce
# yum install -y <FQPN>
yum install -y docker-ce-18.03.1.ce

# 启动并加入开机启动
systemctl start docker
systemctl enable docker

# 验证安装是否成功(有 clientservice 两部分表示 docker 安装启动都成功了)
docker version

Client:
Version: 18.03.1-ce
API version: 1.37
Go version: go1.9.5
Git commit: 9ee9f40
Built: Thu Apr 26 07:20:16 2018
OS/Arch: linux/amd64
Experimental: false
Orchestrator: swarm

Server:
Engine:
Version: 18.03.1-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.9.5
Git commit: 9ee9f40
Built: Thu Apr 26 07:23:58 2018
OS/Arch: linux/amd64
Experimental: false

更改配置(如果有必要)

sudo vim /lib/systemd/system/docker.service

ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --graph=/home/docker/data

# 你可能会用到代理(如果原先没有Environment,可以添加)
Environment="HTTP_PROXY=http://0.0.0.0:8123" "HTTPS_PROXY=http://0.0.0.0:8123" "NO_PROXY=localhost,127.0.0.1,::1"

重启 docker 使配置生效

sudo systemctl daemon-reload
sudo systemctl restart docker

安装 Docker-Compose

通过访问 https://github.com/docker/compose/releases/latest 得到最新的 docker-compose 版本(例如:1.23.2),然后执行一下命令安装 docker-compose

# 下载最新版本的 docker-compose 到 /usr/bin 目录下
curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/bin/docker-compose

# 给 docker-compose 授权
chmod +x /usr/bin/docker-compose

FAQ

1、yum update -y 失败

 
[root@localhost ~]# yum update -y
Loaded plugins: fastestmirror, langpacks
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"


 One of the configured repositories failed (Unknown),
 and yum doesn''t have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Disable the repository, so yum won''t use it by default. Yum will then
        just ignore the repository until you permanently enable it again or use
        --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>

     4. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: base/7/x86_64

如果遇到上面的错误,通过修改 /etc/resolv.conf,添加如下内容,再次执行 yum update -y

 
nameserver 8.8.8.8
search localdomain

2、yum install -y docker-ce-18.03.1.ce 失败

 
Transaction check error:
  file /usr/bin/docker from install of docker-ce-18.03.1.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
  file /usr/bin/docker-containerd from install of docker-ce-18.03.1.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
  file /usr/bin/docker-containerd-shim from install of docker-ce-18.03.1.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
  file /usr/bin/dockerd from install of docker-ce-18.03.1.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64

卸载旧版本的包

 
yum erase docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64

再次安装 docker

 
yum install -y docker-ce-18.03.1.ce

 

CentOS 7 系统 安装docker及docker compose 组件

CentOS 7 系统 安装docker及docker compose 组件

概述

本章将详细介绍在CentOS7.0系统下如何安装docker,分为在线安装和离线安装两部分。目前,CentOS仅发行版本中的内核支持Docker。推荐使用CentOS 7.0及以上版本,64位操作系统、系统内核版本为3.10以上。

在线安装Docker

1)首先查看CentOS版本是否要求。若不符合版本要求,请升级系统版本

cat /etc/redhat-release

2)安装依赖包

yum install -y yum-utils device-mapper-persistent-data lvm2

3)添加软件源信息

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

4)更新yum缓存

yum makecache fast

5)安装Docker-CE

yum -y install docker-ce

6)启动docker后台服务

systemctl start docker

7)查验docker是否安装成功

docker version

8)安装docker-compose

curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

9)赋执行权限

chmod +x /usr/local/bin/docker-compose

10)查验docker-compose是否安装成功

docker-compose version

12)设置docker服务开机自启动

systemctl enable docker

离线安装Docker

1)获取docker离线安装包,形如centos-local.tgz压缩包。(请联系我获取)

2)将离线包上传到服务器的root目录下

3)进入root目录,解压.tgz包

cd /root
tar -xvzf centos-local.tgz

4)安装createrepo

cd /root/docker-ce-local
rpm -ivh createrepo-0.9.9-28.el7.noarch.rpm

5)新增docker-ce-local.repo源文件,写入以下内容

vi /etc/yum.repos.d/docker-ce-local.repo

[docker-ce-local]

  name=Local Yum

  baseurl=file:///root/docker-ce-local/

  gpgcheck=1

  gpgkey=file:///root/docker-ce-local/gpg

  enabled=1

6)生成源索引及缓存

createrepo /root/docker-ce-local
yum makecache

7)安装docker-ce

yum install docker-ce

8)启动并测试

systemctl start docker
docker version

9)加入开机自启

systemctl enable docker

10)安装docker-compose

cp /root/docker-ce-local/docker-compose /usr/bin/

11)赋执行权限

chmod +x /usr/bin/docker-compose

12)验证版本

docker-compose version

 

CentOS 8.0 64位安装Docker 以及 Docker Compose

CentOS 8.0 64位安装Docker 以及 Docker Compose

1. 安装Docker

执行sudo curl -sSL https://get.daocloud.io/docker | sh
执行完之后输入docker -v 查看是否有对应的版本号,有的话则表明安装成功

在这里插入图片描述

2. 安装Docker Compose

官方文档

  1. 执行sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  2. 执行sudo chmod +x /usr/local/bin/docker-compose。这一步是添加执行权限
  3. 接下来运行docker-compose --version,查看是否出现版本号,如果有表明安装成功。
  4. 如果第三步运行失败,执行sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose命令,把Docker Compose换个路径存储,再执行第三步看看是否成功。

centos 上安装docker和docker-compose

centos 上安装docker和docker-compose


要安装docker前,先看一下你的linux服务器是否支持docker 。如果内核版本过低,就会出现问题。建议先升级内核。


可参考上篇文章。


升级完后。就可以安装docker了。


先yum update


然后:yuminstalldocker-io


再:servicedockerstart


启动成功,即可查看docker info


设置开机启动:chkconfig docker on

若要卸载:yumlist installed | grep docker

yum - y remove docker-engine.x86_64

rum-rf /var/lib/docker

安装docker-compose

先:yum install python-pip.noarch


#对安装好的pip进行一次升级
sudo pip install --upgrade pip


再:pip install docker-compose

另一种方式:
curl -L https://github.com/docker/compose/releases/download/1.8.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
若/usr/bin 下找不到命令,则cp /usr/local/bin/docker-compose /usr/bin/ 下即可

最后docker-compose -version 查看
官方文档:https://docs.docker.com/engine/installation/linux/centos/

关于一行命令安装 docker 和 docker-compose (CentOS7)一键命令安装docker脚本的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于CentOS 7 安装 Docker 和 Docker-Compose、CentOS 7 系统 安装docker及docker compose 组件、CentOS 8.0 64位安装Docker 以及 Docker Compose、centos 上安装docker和docker-compose等相关内容,可以在本站寻找。

本文标签: