Linux上安装Docker

本文介绍 Docker CE 简单的安装。
先附上我的安装环境:VMware14+centos7

1.移除旧的版本(如果之前没有安装过,可以跳过这步):

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine

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.测试运行hello-world

docker run hello-world

执行之后如果出现下面的提示就成功了:

[root@localhost ~]# docker run hello-world

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/

[root@localhost ~]# 

下面附上一些常用的Docker命令(下列ID均为CONTAINER ID字段的值,可用Docker ps -a查看):

docker images       查看镜像
docker pull centos:7.5.1804  拉取镜像
docker  rmi  【-f   强制删除】  镜像名字:版本  或者镜像ID
docker save -o my_centos_7.5.1804.tar centos:7.5.1804        将镜像保存到哪个文件
docker load --input my_centos_7.5.1804       加载镜像
docker ps    查询所有运行的容器
docker ps  -a   查询所有的容器
docker   exec  -it[开启一个伪终端]  ID  /bin/bash   进入容器
yum install -y net-tools   安装网络工具,比如可以执行ifconfig
docker   create  -it  centos:7.5.1804   创建容器,跟run区别主要在exit
docker  run     -it  centos:7.5.1804   创建并运行容器,跟create区别主要在exit
docker   start  ID   启动容器
docker  rm  ID  删除容器 
docker  stop ID   停止容器
exit  退出容器(如果是create容器并启动,退出之后可以查看得到正在运行的容器,如果是run则会一并退出,查看不到正在运行的容器)

删除 Docker CE,执行以下命令来删除 Docker CE:

 yum remove docker-ce
 rm -rf /var/lib/docker

镜像可以去官网上查找: https://www.docker.com/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值