首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Docker安装

Docker安装

作者头像
py3study
发布2018-08-02 15:37:34
1.1K0
发布2018-08-02 15:37:34
举报
文章被收录于专栏:python3python3

安装之前,我们首先确保自己的linux系统内核版本高于3.10,并且系统是64位,才能体验Docker。所以我用的是Centos7.3

直接yum安装就可以了

[root@localhost ~]# yum install -y docker-io

默认用的是国外的镜像源,所以网络非常慢

需要添加国内镜像源才行

通过 Docker 官方镜像加速,中国区用户能够快速访问最流行的 Docker 镜像。该镜像托管于中国大陆,本地用户现在将会享受到更快的下载速度和更强的稳定性,从而能够更敏捷地开发和交付 Docker 化应用。

为了永久保留更改,需要修改配置文件 /etc/docker/daemon.json 文件并添加上 registry-mirrors 键值。

[root@localhost ~]# vim /etc/docker/daemon.json

默认内容是{},修改效果如下:

{
  "registry-mirrors": ["https://registry.docker-cn.com"]
}

重启docker服务

[root@localhost ~]# systemctl restart docker

查看docker进程是否存在

[root@localhost ~]# ps -aux | grep docker
root      3697  0.3  1.3 629816 25920 ?        Ssl  21:47   0:00 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current --selinux-enabled --log-driver=journald --signature-verification=false
root      3701  0.0  0.4 263768  8212 ?        Ssl  21:47   0:00 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim docker-containerd-shim --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --runtime docker-runc --runtime-args --systemd-cgroup=true
root      3802  0.0  0.0 112664   972 pts/0    R+   21:48   0:00 grep --color=auto docker

先安装一个软件包,用来支持docker命令补全的

[root@localhost ~]# yum install -y bash-completion

注意:必须要退出终端,重新登录一次才能生效。

查看本地已有的镜像 Docker images

[root@localhost ~]# docker images

Cannot connect to the Docker daemon. Is the docker daemon running on this host?

上面提示说明没有镜像

那么就去搜索一个镜像,比如ubuntu

[root@localhost ~]# docker search ubuntu

结果如下:

3.PNG
3.PNG

下载第一个,就是一个基本的ubuntu系统

[root@localhost ~]# docker pull docker.io/ubuntu

再次使用命令查看本地镜像,就可以看到下载的镜像了

[root@localhost ~]# docker images

REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE

docker.io/ubuntu                        latest              20c44cd7596f        2 weeks ago         122.8 MB

启动一个基于docker.io/ubuntu的容器

[root@localhost ~]# docker run -it --name test-ubuntu docker.io/ubuntu /bin/bash
root@1cfd7b760ee0:/#

-it 交互式容器 退出命令窗口容器就停止运行了

-d 守护容器,就是后台运行,退出命令窗口容器也不会停止

--name 为容器命名

docker.io/ubuntu 镜像名

/bin/bash 进入bash命令行

root@1cfd7b760ee0:/# 表示已经进入了容器内部

如果需要退出,可以使用命令exit

root@1cfd7b760ee0:/# exit
exit
[root@localhost ~]#

执行exit, 此时, 运行docker ps -a 查看容器, 发现状态为Exited, 运行中的状态是Up

3.PNG
3.PNG

docker ps 命令, 查看运行中的容器

docker ps -a命令, 查看全部的容器, 包括运行中和已停止运行的容器

删除状态为Exited, 已停止运行的容器

通过容器名称删除已经停止运行的容器(test-centos为docker run命令中给容器的命名)

[root@localhost ~]# docker rm test-ubuntu
test-ubuntu
[root@localhost ~]#

通过容器ID删除已经停止运行的容器

docker rm 1cfd7b760ee0 这两个命令效果一样, 1cfd7b760ee0是containerID

强制删除状态为Up, 正在运行中的容器

[root@localhost ~]# docker rm -f test-ubuntu
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-12-06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器镜像服务
容器镜像服务(Tencent Container Registry,TCR)为您提供安全独享、高性能的容器镜像托管分发服务。您可同时在全球多个地域创建独享实例,以实现容器镜像的就近拉取,降低拉取时间,节约带宽成本。TCR 提供细颗粒度的权限管理及访问控制,保障您的数据安全。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档