linux和Ubuntu上分别安装docker

一、linux在线安装docker

(1)卸载旧版本,如果是第一次安装则不需要执行此步

systemctl stop docker
yum remove docker -y

(2)安装依赖

yum -y install yum-utils

(3)安装配置docker源

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

(4)安装docker-ce

# 更新yum源
yum update
# 查看可安装的版本
yum list docker-ce --showduplicates | sort -r
# 安装指定版本
yum install docker-ce-17.09.0.ce -y

(4)启动服务

systemctl start docker
systemctl enable docker

(5)查看安装版本

docker version

(6)运行hello-world,检验docker是否安装成功

# 拉取hello-world镜像
docker pull hello-world
# 运行
docker run hello-world
遇到的问题

Ⅰ yum中途手动停掉后出现以下错误
Another app is currently holding the yum lock; waiting for it to exit
原因:
上次运行安装或更新没有正常完成,另外一个程序正在使用该程序,从而导致资源锁不可用。
解决方法:
把进程给杀掉才行

ps aux | grep yum
# pid为上一步查出的进程号
kill -s 9 pid

或删掉以下两个文件

sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock

Ⅱ 安装完docker后运行hello-world出现以下问题

Unable to find image ‘hello-world:latest’ locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: TLS handshake timeout.

原因:

docker在本地没有找到hello-world镜像,也没有从docker仓库中拉取镜像,出项这个问题的原因:是因为docker服务器在国外,我们在国内无法正常拉取镜像,所以就需要我们为docker设置国内阿里云的镜像加速器;

需要修改配置文件 /etc/docker/daemon.json

解决步骤:
(1)在/etc/docker目录下新建daemon.json文件

[root@localhost ~]# cd /etc/docker/
[root@localhost docker]# ll
总用量 4
-rw-------. 1 root root 244 519 11:22 key.json
[root@localhost docker]# touch daemon.json
[root@localhost docker]# ll
总用量 4
-rw-r--r--. 1 root root   0 519 11:29 daemon.json
-rw-------. 1 root root 244 519 11:22 key.json

(2)修改daemon.json的权限

[root@localhost docker]# chmod 777 daemon.json
[root@localhost docker]# ll
总用量 4
-rwxrwxrwx. 1 root root   0 519 11:29 daemon.json
-rw-------. 1 root root 244 519 11:22 key.json

(3)修改daemon.json的内容

[root@localhost docker]# vi daemon.json 
# 写入以下内容
{
"registry-mirrors":["https://alzgoonw.mirror.aliyuncs.com"]
}

(4)重启docker服务

[root@localhost docker]# systemctl restart docker

(5)运行hello-world

[root@localhost docker]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete 
Digest: sha256:6a65f928fb91fcfbc963f7aa6d57c8eeb426ad9a20c7ee045538ef34847f44f1
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/
二、Ubuntu离线安装docker
1. Ubuntu配置网络

(1)点击右上角图标选择最后一项
在这里插入图片描述
(2)选择ADD
在这里插入图片描述
(3)默认,点击创建
在这里插入图片描述
(4)Method选择Manual,地址填正确,点击Save
在这里插入图片描述
(5)点击切换到自己新建的静态连接
在这里插入图片描述
(6)重启网卡
在这里插入图片描述
(7)验证
在这里插入图片描述

2. 修改root密码

Ubuntu安装后,root用户默认是被锁定了的,不允许登录,也不允许执行“su命令到root”。对于桌面用户而言,这样可以提高安全性。但对于服务器可以设置成允许“su命令到root,但不允许root用户直接登录”。

因而对于Ubuntu输入su命令提示认证失败这个问题,可以通过重新设置root密码来解决。

$sudo passwd
[sudo] password for xxx: <--- 输入安装时那个用户的密码
Enter new UNIX password: <--- 新的root用户密码
Retype new UNIX password: <--- 重复新的root用户密码
passwd:已成功更新密码

在这里插入图片描述

3.安装完SSH后才能连接Xshell

切换到root用户,安装东西前先更新源,因为以前的源很旧了

apt update

(1)安装sshd服务

openssh的服务端:sshd
openssh的客户端:ssh
ssh运行在客户端,sshd运行在服务端

Install后面加-y参数代表所有要你选择的地方都选择yes
在这里插入图片描述
(2)用ps查是否有sshd的进程,有则代表安装成功
在这里插入图片描述
(3)现在就可以连接xshell(协议是SSH2)、xftp(协议是SFTP over SSH)等工具了
连接xftp 时默认的协议是FTP,也可以不改默认协议,但需要在虚拟机上安装sftp服务

apt-get install -y sftp
4.安装docker

(1)新建存放安装包的目录install_dir(确保此文件夹是root用户属组)

root@ubuntu:~# mkdir install_dir

(2)用FXP连接服务器(服务器就代表虚拟机),将docker压缩包传到install_dir目录下

为了保险起见,在FXP等传输工具中将 会话->传输模式,手动改为二进制的方式

root@ubuntu:~# cd install_dir/
root@ubuntu:~/install_dir# ls
docker-ce_17.09.0-ce-0-ubuntu_amd64.deb

(3)安装docker

dpkg是一个Debian的一个命令行工具,它可以用来安装、删除、构建和管理Debian的软件包。

root@ubuntu:~/install_dir# dpkg -i docker-ce_17.09.0-ce-0-ubuntu_amd64.deb 

(4)运行hello-world验证docker是否安装成功

docker run hello-world

(此处又会出现镜像找不到的情况,根据在线安装时提出的解决办法更换镜像就好了)
(5)将docker设为开机自启

systemctl enable docker
遇到的问题

Ⅰ安装sshd时出现以下问题
Package ssh is not available, but is referred to by another package 错误
(1)原因
这个问题的原因是ubuntu的/etc/apt/source.list中的源比较旧了,需要更新一下
(2)解决方法

 sudo apt-get -y update

(3)更新完毕之后,在使用apt-get就没有问题了。

Ⅱ 安装ssh时出现镜像问题需要换镜像
Ubuntu更换源
原因:
ubuntu自带的源不好用,或者有问题
解决方法:
(1)修改/etc/apt/sources.list文件

#此种编辑非常好用,比vi好多了
 sudo gedit /etc/apt/sources.list

如果不能执行需要安装gedit

 sudo apt-get install gedit

(2)写入中科大的源(尝试的所有中最可靠的)

deb http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse

在这里插入图片描述
(3)更新

sudo apt-get update

Ⅲ Ubuntu中root用户无法连接xshell
(1)修改 /etc/ssh/sshd_config 文件把PermitRootLogin Prohibit-password 注释掉
新添加:PermitRootLogin yes

注意:改的是sshd_config。ssh_config是客户端,sshd_config是服务端
在这里插入图片描述
(2)重启ssh服务

/etc/init.d/ssh restart
或
systemctl restart sshd

在这里插入图片描述
(3)可以成功连接了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值