CentOS 安装 docker详解

1\执行如下命令,确保 yum 包更新到最新

login as: root
root@192.168.182.132's password:
Last login: Wed Aug 31 20:09:46 2022
[root@controller ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@controller ~]# yum update
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirror.sjtu.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 epel-release.noarch.0.7-11 将被 升级
---> 软件包 epel-release.noarch.0.7-14 将被 更新

---> 软件包 python-perf.x86_64.0.3.10.0-1160.71.1.el7 将被 升级
---> 软件包 python-perf.x86_64.0.3.10.0-1160.76.1.el7 将被 更新
--> 解决依赖关系完成

依赖关系解决

================================================================================
 Package              架构      版本                           源          大小
================================================================================
正在安装:
 kernel               x86_64    3.10.0-1160.76.1.el7           updates     50 M
正在更新:
 epel-release         noarch    7-14                           epel        15 k
 gvfs                 x86_64    1.36.2-7.el7_9                 updates    354 k
 gvfs-afc             x86_64    1.36.2-7.el7_9                 updates     74 k
 gvfs-afp             x86_64    1.36.2-7.el7_9                 updates     88 k
 gvfs-archive         x86_64    1.36.2-7.el7_9                 updates     42 k
 gvfs-client          x86_64    1.36.2-7.el7_9                 updates    799 k
 gvfs-fuse            x86_64    1.36.2-7.el7_9                 updates     46 k
 gvfs-goa             x86_64    1.36.2-7.el7_9                 updates     78 k
 gvfs-gphoto2         x86_64    1.36.2-7.el7_9                 updates     78 k
 gvfs-mtp             x86_64    1.36.2-7.el7_9                 updates     78 k
 gvfs-smb             x86_64    1.36.2-7.el7_9                 updates     60 k
 kernel-tools         x86_64    3.10.0-1160.76.1.el7           updates    8.2 M
 kernel-tools-libs    x86_64    3.10.0-1160.76.1.el7           updates    8.1 M
 lldpad               x86_64    1.0.1-7.git036e314.el7_9       updates    283 k
 microcode_ctl        x86_64    2:2.1-73.14.el7_9              updates    4.5 M
 python-perf          x86_64    3.10.0-1160.76.1.el7           updates    8.2 M

事务概要
================================================================================
安装   1 软件包
升级  16 软件包

总计:81 M
Is this ok [y/d/N]: y
Downloading packages:
警告:/var/cache/yum/x86_64/7/epel/packages/epel-release-7-14.noarch.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 352c64e5: NOKEY
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 检索密钥
导入 GPG key 0x352C64E5:
 用户ID     : "Fedora EPEL (7) <epel@fedoraproject.org>"
 指纹       : 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
 软件包     : epel-release-7-11.noarch (@extras)
 来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
是否继续?[y/N]:y
Running transaction check

  lldpad.x86_64 0:1.0.1-7.git036e314.el7_9
  microcode_ctl.x86_64 2:2.1-73.14.el7_9
  python-perf.x86_64 0:3.10.0-1160.76.1.el7

完毕!
[root@controller ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@controller ~]#

2、如果安装过旧版本的话,执行如下命令卸载旧版本(没哟可以跳过此步骤)
yum remove docker docker-common docker-selinux docker-engine

3:安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的

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

[root@controller ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirror.sjtu.edu.cn
软件包 yum-utils-1.1.31-54.el7_8.noarch 已安装并且是最新版本
软件包 device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64 已安装并且是最新版本
软件包 7:lvm2-2.02.187-6.el7_9.5.x86_64 已安装并且是最新版本
无须任何处理

4:设置yum源(这里使用的阿里云镜像源地址)
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

[root@controller ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件:fastestmirror
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

5:查看那个yum源最快,可以看到阿里的最快

[root@controller ~]# yum makecache fast                                         已加载插件:fastestmirror
/var/run/yum.pid 已被锁定,PID 为 53841 的另一个程序正在运行。
Another app is currently holding the yum lock; waiting for it to exit...
  另一个应用程序是:PackageKit
    内存:262 M RSS (1.4 GB VSZ)
    已启动: Wed Aug 31 20:20:52 2022 - 00:04之前
    状态  :睡眠中,进程ID:53841
Another app is currently holding the yum lock; waiting for it to exit...
  另一个应用程序是:PackageKit
    内存:262 M RSS (1.4 GB VSZ)
    已启动: Wed Aug 31 20:20:52 2022 - 00:06之前
    状态  :睡眠中,进程ID:53841
Another app is currently holding the yum lock; waiting for it to exit...
  另一个应用程序是:PackageKit
    内存:262 M RSS (1.4 GB VSZ)
    已启动: Wed Aug 31 20:20:52 2022 - 00:08之前
    状态  :睡眠中,进程ID:53841
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                     | 8.5 kB     00:00
 * epel: mirrors.tuna.tsinghua.edu.cn
base                                                     | 3.6 kB     00:00
docker-ce-stable                                         | 3.5 kB     00:00
extras                                                   | 2.9 kB     00:00
updates                                                  | 2.9 kB     00:00
元数据缓存已建立
[root@controller ~]#

6:查看docker的版本,可以选择指定版本安装

[root@controller ~]# yum list docker-ce --showduplicates | sort -r
已加载插件:fastestmirror
可安装的软件包
Loading mirror speeds from cached hostfile
 * epel: mirror.sjtu.edu.cn
docker-ce.x86_64            3:20.10.9-3.el7                     docker-ce-stable
docker-ce.x86_64            3:20.10.8-3.el7                     docker-ce-stable
docker-ce.x86_64            3:20.10.7-3.el7                     docker-ce-stable
docker-ce.x86_64            3:20.10.6-3.el7                     docker-ce-stable
docker-ce.x86_64            3:20.10.5-3.el7                     docker-ce-stable
docker-ce.x86_64            3:20.10.4-3.el7                     docker-ce-stable
docker-ce.x86_64            3:20.10.3-3.el7                     docker-ce-stable
docker-ce.x86_64            3:20.10.2-3.el7                     docker-ce-stable
docker-ce.x86_64            3:20.10.17-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.16-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.15-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.14-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.1-3.el7                     docker-ce-stable
docker-ce.x86_64            3:20.10.13-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.12-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.11-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.10-3.el7                    docker-ce-stable
docker-ce.x86_64            3:20.10.0-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.9-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.8-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.7-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.6-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.5-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.4-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.3-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.2-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.15-3.el7                    docker-ce-stable
docker-ce.x86_64            3:19.03.14-3.el7                    docker-ce-stable
docker-ce.x86_64            3:19.03.1-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.13-3.el7                    docker-ce-stable
docker-ce.x86_64            3:19.03.12-3.el7                    docker-ce-stable
docker-ce.x86_64            3:19.03.11-3.el7                    docker-ce-stable
docker-ce.x86_64            3:19.03.10-3.el7                    docker-ce-stable
docker-ce.x86_64            3:19.03.0-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.9-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.8-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.7-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.6-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.5-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.4-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.3-3.el7                     docker-ce-stable
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
[root@controller ~]#

7:安装docker
#安装指定版本 其中VERSION_STRING 为版本号
sudo yum install docker-ce-<VERSION_STRING>

[root@controller ~]# yum -y install docker-ce
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirror.sjtu.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 docker-ce.x86_64.3.20.10.17-3.el7 将被 安装
--> 正在处理依赖关系 container-selinux >= 2:2.74,它
---> 软件包 fuse3-libs.x86_64.0.3.6.1-4.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

================================================================================
 Package                架构   版本                      源                大小
================================================================================
正在安装:
 docker-ce              x86_64 3:20.10.17-3.el7          docker-ce-stable  22 M
为依赖而安装:
 container-selinux      noarch 2:2.119.2-1.911c772.el7_8 extras            40 k
 containerd.io          x86_64 1.6.8-3.1.el7             docker-ce-stable  33 M
 docker-ce-cli          x86_64 1:20.10.17-3.el7          docker-ce-stable  29 M
 docker-ce-rootless-extras
                        x86_64 20.10.17-3.el7            docker-ce-stable 8.2 M
 docker-scan-plugin     x86_64 0.17.0-3.el7              docker-ce-stable 3.7 M
 fuse-overlayfs         x86_64 0.7.2-6.el7_8             extras            54 k
 fuse3-libs             x86_64 3.6.1-4.el7               extras            82 k
 slirp4netns            x86_64 0.4.3-4.el7_8             extras            81 k

事务概要
================================================================================
安装  1 软件包 (+8 依赖软件包)

总下载量:97 M
安装大小:394 M
Downloading packages:
(1/9): container-selinux-2.119.2-1.911c772.el7_8.noarch.rp |  40 kB   00:00
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/containerd.io-1.6.8-3.1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
containerd.io-1.6.8-3.1.el7.x86_64.rpm 的公钥尚未安装
(2/9): containerd.io-1.6.8-3.1.el7.x86_64.rpm              |  33 MB   00:08
(3/9): docker-ce-20.10.17-3.el7.x86_64.rpm                 |  22 MB   00:09
(4/9): docker-ce-rootless-extras-20.10.17-3.el7.x86_64.rpm | 8.2 MB   00:02
(5/9): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm             |  54 kB   00:00
(6/9): fuse3-libs-3.6.1-4.el7.x86_64.rpm                   |  82 kB   00:00
(7/9): slirp4netns-0.4.3-4.el7_8.x86_64.rpm                |  81 kB   00:00
(8/9): docker-scan-plugin-0.17.0-3.el7.x86_64.rpm          | 3.7 MB   00:02
(9/9): docker-ce-cli-20.10.17-3.el7.x86_64.rpm             |  29 MB   00:07
--------------------------------------------------------------------------------
总计                                               5.9 MB/s |  97 MB  00:16
从 https://mirrors.aliyun.com/docker-ce/linux/centos/gpg 检索密钥
导入 GPG key 0x621E9F35:
 用户ID     : "Docker Release (CE rpm) <docker@docker.com>"
 指纹       : 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 来自       : https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : docker-scan-plugin-0.17.0-3.el7.x86_64                      1/9
 
  验证中      : docker-scan-plugin-0.17.0-3.el7.x86_64                      8/9
  验证中      : fuse-overlayfs-0.7.2-6.el7_8.x86_64                         9/9

已安装:
  docker-ce.x86_64 3:20.10.17-3.el7

作为依赖被安装:
  container-selinux.noarch 2:2.119.2-1.911c772.el7_8
  containerd.io.x86_64 0:1.6.8-3.1.el7
  docker-ce-cli.x86_64 1:20.10.17-3.el7
  docker-ce-rootless-extras.x86_64 0:20.10.17-3.el7
  docker-scan-plugin.x86_64 0:0.17.0-3.el7
  fuse-overlayfs.x86_64 0:0.7.2-6.el7_8
  fuse3-libs.x86_64 0:3.6.1-4.el7
  slirp4netns.x86_64 0:0.4.3-4.el7_8

完毕!
[root@controller ~]# pwd
/root
[root@controller ~]# mkdir /dockdir
[root@controller ~]# cd /dockdir/
[root@controller dockdir]# sudo yum install docker-ce-18.06.3.ce-3.el7 --downloadonly --downloaddir=/dockdir
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirror.nju.edu.cn
匹配 docker-ce-18.06.3.ce-3.el7.x86_64 的软件包已经安装。正在检查更新。
无须任何处理
[root@controller dockdir]# sudo yum install docker-ce --downloadonly --downloaddir=/dockdir
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirror.sjtu.edu.cn
软件包 3:docker-ce-20.10.17-3.el7.x86_64 已安装并且是最新版本
无须任何处理

启动,关闭,开机启动docker

  • 启动docker
    service docker start
  • 验证docker启动成功
    docker version
[root@controller dockdir]# service docker start
Redirecting to /bin/systemctl start docker.service
[root@controller dockdir]# docker version
Client: Docker Engine - Community
 Version:           20.10.17
 API version:       1.41
 Go version:        go1.17.11
 Git commit:        100c701
 Built:             Mon Jun  6 23:05:12 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.17
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.11
  Git commit:       a89b842
  Built:            Mon Jun  6 23:03:33 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.8
  GitCommit:        9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[root@controller dockdir]#

  • 设置docker开机启动
    systemctl enable docker
  • 停止docker
    systemctl stop docker
[root@controller dockdir]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@controller dockdir]# systemctl stop docker
Warning: Stopping docker.service, but it can still be activated by:
  docker.socket
[root@controller dockdir]#

宿主机新建Nextcloud文件夹,Nextcloud文件夹用于映射Nextcloud容器的存储路径。

[root@controller dockdir]# mkdir -p /home/docker/nextcloud
[root@controller dockdir]# cd /home/docker/
[root@controller docker]# ls
nextcloud
[root@controller docker]# docker run -d --name mysql \
>     -v /root/nextcloud/mysql:/var/lib/mysql \
>     -e MYSQL_ROOT_PASSWORD=password \
>     -e MYSQL_DATABASE=nextcloud \
>     -e MYSQL_USER=nextcloud \
>     -e MYSQL_PASSWORD=password \
>     -p 3307:3306 \
>     --restart=always \
> ^C  mysql:8.0
[root@controller docker]# cd nextcloud/
[root@controller nextcloud]# ls
[root@controller nextcloud]# mkdir mysql
[root@controller nextcloud]# ll
总用量 0
drwxr-xr-x 2 root root 6 831 20:38 mysql
[root@controller nextcloud]# cd ..
[root@controller docker]# ls
nextcloud
[root@controller docker]# ll
总用量 0
drwxr-xr-x 3 root root 19 831 20:38 nextcloud

安装Docker版MySQL与Nextcloud


[root@controller docker]# docker run -d --name mysql \
>     -v /home/docker/nextcloud/mysql:/var/lib/mysql \
>     -e MYSQL_ROOT_PASSWORD=password \
>     -e MYSQL_DATABASE=nextcloud \
>     -e MYSQL_USER=nextcloud \
>     -e MYSQL_PASSWORD=password \
>     -p 3307:3306 \
>     --restart=always \
>     mysql:8.0
Unable to find image 'mysql:8.0' locally
8.0: Pulling from library/mysql
492d84e496ea: Pull complete
bbe20050901c: Pull complete
e3a5e171c2f8: Pull complete
c2cedd8aa061: Pull complete
d6a485af4cc9: Pull complete
ee16a57baf60: Pull complete
64bab9180d2a: Pull complete
c3aceb7e4f48: Pull complete
269002e5cf58: Pull complete
d5abeb1bd18e: Pull complete
cbd79da5fab6: Pull complete
Digest: sha256:cdf3b62d78d1bbb1d2bd6716895a84014e00716177cbb7e90f6c6a37a21dc796
Status: Downloaded newer image for mysql:8.0
b3e7df01fd0fc119e3072cb40476d5f1938d0f2d222377a635daeeef9d915611
[root@controller docker]# docker ps -a
CONTAINER ID   IMAGE       COMMAND                  CREATED         STATUS         PORTS                                                  NAMES
b3e7df01fd0f   mysql:8.0   "docker-entrypoint.s…"   9 seconds ago   Up 7 seconds   33060/tcp, 0.0.0.0:3307->3306/tcp, :::3307->3306/tcp   mysql
[root@controller docker]# ls
nextcloud
[root@controller docker]# pwd
/home/docker
[root@controller docker]# cd nextcloud/
[root@controller nextcloud]# ls
mysql
[root@controller nextcloud]# cd mysql/
[root@controller mysql]# ls
auto.cnf       client-cert.pem    ibtmp1        nextcloud           sys
binlog.000001  client-key.pem     #innodb_redo  performance_schema  undo_001
binlog.000002  #ib_16384_0.dblwr  #innodb_temp  private_key.pem     undo_002
binlog.index   #ib_16384_1.dblwr  mysql         public_key.pem
ca-key.pem     ib_buffer_pool     mysql.ibd     server-cert.pem
ca.pem         ibdata1            mysql.sock    server-key.pem
[root@controller mysql]# cd ..
[root@controller nextcloud]# ls
mysql
[root@controller nextcloud]# ll
总用量 4
drwxr-xr-x 8 polkitd root 4096 831 20:40 mysql
[root@controller nextcloud]# dir data
dir: 无法访问data: 没有那个文件或目录
[root@controller nextcloud]# mkdir data
[root@controller nextcloud]# ls
data  mysql
[root@controller nextcloud]# ll
总用量 4
drwxr-xr-x 2 root    root    6 831 20:41 data
drwxr-xr-x 8 polkitd root 4096 831 20:40 mysql
[root@controller nextcloud]#
[root@controller nextcloud]# docker run -d --name nextcloud \
>     -v /home/docker/nextcloud/data:/var/www/html \
>     --link mysql:mysql \
>     --restart=always \
>     -p 8888:80
"docker run" requires at least 1 argument.
See 'docker run --help'.

Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Run a command in a new container
[root@controller nextcloud]# docker run -d --name nextcloud \
>     -v /home/docker/nextcloud/data:/var/www/html \
>     --link mysql:mysql \
>     --restart=always \
>     -p 8888:80 \
>     -p 8443:443  nextcloud
Unable to find image 'nextcloud:latest' locally
latest: Pulling from library/nextcloud
1efc276f4ff9: Pull complete
3239fd0772e9: Pull complete
52ccb8ba6c06: Pull complete
e907707b68ee: Pull complete
f001901b2b66: Pull complete
3926f8e80674: Pull complete
abc6b8b3381c: Pull complete
a855b6d05008: Pull complete
621c0aaa2021: Pull complete
a253b252d59e: Pull complete
7a0ed5f4655c: Pull complete
3a1e772ff0b9: Pull complete
9e79b6c60dfc: Pull complete
69433f1bdecd: Pull complete
846ae4571330: Pull complete
fbc2c69bb404: Pull complete
bee57d0cfcc4: Pull complete
03f1c46a2799: Pull complete
287fb9634980: Pull complete
9fb192723bca: Pull complete
Digest: sha256:e772f305225695a2a510d547f58b0da61c18e774176f32e82ad181472f22ae1a
Status: Downloaded newer image for nextcloud:latest
3897d7d482a169dd64d49fab05c8a01a51a61b3dccfe750c14c22d830ca77a4c
docker: Error response from daemon: driver failed programming external connectiv                             ity on endpoint nextcloud (bc49fa4614d494bc4af085c8ce701e2e5dba389608b05d0340f0b                             0058392654e): Error starting userland proxy: listen tcp4 0.0.0.0:8888: bind: add                             ress already in use.
[root@controller nextcloud]# docker ps -a
CONTAINER ID   IMAGE       COMMAND                  CREATED          STATUS                                       PORTS                                                  NAMES
3897d7d482a1   nextcloud   "/entrypoint.sh apac…"   4 minutes ago    Created                                                                                             nextcloud
b3e7df01fd0f   mysql:8.0   "docker-entrypoint.s…"   23 minutes ago   Up 23 minut                             es   33060/tcp, 0.0.0.0:3307->3306/tcp, :::3307->3306/tcp   mysql
[root@controller nextcloud]# docker ps -a
CONTAINER ID   IMAGE       COMMAND                  CREATED          STATUS          PORTS                                                  NAMES
3897d7d482a1   nextcloud   "/entrypoint.sh apac…"   5 minutes ago    Created                                                                nextcloud
b3e7df01fd0f   mysql:8.0   "docker-entrypoint.s…"   24 minutes ago   Up 24 minutes   33060/tcp, 0.0.0.0:3307->3306/tcp, :::3307->3306/tcp   mysql
[root@controller nextcloud]#

删除docker重建

[root@controller nextcloud]# docker ps -a
CONTAINER ID   IMAGE       COMMAND                  CREATED          STATUS          PORTS                                                  NAMES
3897d7d482a1   nextcloud   "/entrypoint.sh apac…"   6 minutes ago    Created                                                                nextcloud
b3e7df01fd0f   mysql:8.0   "docker-entrypoint.s…"   25 minutes ago   Up 25 minutes   33060/tcp, 0.0.0.0:3307->3306/tcp, :::3307->3306/tcp   mysql
[root@controller nextcloud]# docker rm 3897d7d482a1
3897d7d482a1
[root@controller nextcloud]# docker ps -a
CONTAINER ID   IMAGE       COMMAND                  CREATED          STATUS          PORTS                                                  NAMES
b3e7df01fd0f   mysql:8.0   "docker-entrypoint.s…"   26 minutes ago   Up 26 minutes   33060/tcp, 0.0.0.0:3307->3306/tcp, :::3307->3306/tcp   mysql
[root@controller nextcloud]# docker run -d --name nextcloud     -v /home/docker/nextcloud/data:/var/www/html     --link mysql:mysql     --restart=always     -p 8088:80     -p 8443:443  nextcloud
65addef32d08232be40662142b3a415713281f82f7dd9c79cd9c4b5d5ef5cead
[root@controller nextcloud]# docker ps -a
CONTAINER ID   IMAGE       COMMAND                  CREATED          STATUS          PORTS                                                                            NAMES
65addef32d08   nextcloud   "/entrypoint.sh apac…"   5 seconds ago    Up 4 seconds    0.0.0.0:8088->80/tcp, :::8088->80/tcp, 0.0.0.0:8443->443/tcp, :::8443->443/tcp   nextcloud
b3e7df01fd0f   mysql:8.0   "docker-entrypoint.s…"   26 minutes ago   Up 26 minutes   33060/tcp, 0.0.0.0:3307->3306/tcp, :::3307->3306/tcp                             mysql
[root@controller nextcloud]#

查看数据库

[root@controller nextcloud]# docker exec -it b3e7df01fd0f /bin/bash
bash-4.4# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
bash-4.4# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.30 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| nextcloud          |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> user nextcloud
    -> ^C
mysql> use nextcloud
Database changed

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值