CentOS7上安装docker

Docker有仓库Repositories、镜像Images和容器Container三大核心,三者可以互相转化

1. 如果系统内有老版本的docker,我们需要先删除之前的docker以及相关依赖

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

或者

yum -y remove docker-ce* containerd.io*

可通过下面的命令来确定是否卸载干净

yum list installed|grep docker

 

2.安装社区版docker

注:不需要事先 yum -y install epel-release

2.1 安装所需要的包

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

CentOS7上安装docker_第1张图片

最后出现 complete 表示安装完成。

2.2 设置稳定的存储库

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

2.3

yum makecache fast
rpm --import https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

 

CentOS7上安装docker_第2张图片

2.4 安装最新的社区版docker

yum -y install docker-ce

CentOS7上安装docker_第3张图片

3. 设置开机自启并启动docker

3.1

systemctl enable docker

 

3.2

mkdir /etc/docker
wget -O /etc/docker/daemon.json http://demo.jumpserver.org/download/docker/daemon.json

3.3.启动docker

systemctl restart docker

4.查看docker版本信息

[root@fastdfs ~]# docker -v
Docker version 19.03.8, build afacb8b
[root@fastdfs ~]#

5.验证

docker run -d -p 5000:5000 -p 3000:80 training/webapp python app.py

查看 docker 容器

CentOS7上安装docker_第4张图片

CentOS7上安装docker_第5张图片

ping 容器ip 可以ping通

CentOS7上安装docker_第6张图片

查看日志

docker logs -f sleepy_euler

CentOS7上安装docker_第7张图片

查看docker网络信息

docker network list

CentOS7上安装docker_第8张图片

[root@fastdfs network-scripts]# docker network list
NETWORK ID          NAME                DRIVER              SCOPE
6b0ab7a98d61        bridge              bridge              local
e77886c99077        host                host                local
c87f86509c08        none                null                local
[root@fastdfs network-scripts]# 
[root@fastdfs network-scripts]# docker network inspect bridge
[
    {
        "Name": "bridge",
        "Id": "6b0ab7a98d615a3b4bd57380945efa492ccffbb9b0ccf312faf7f68917e49457",
        "Created": "2020-05-06T23:00:49.78008304+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "9fc31c8e347f928d0f8d9c2005b1e2b28c79a1340f5b606f6f6ec14bce91fa3c": {
                "Name": "sleepy_euler",
                "EndpointID": "7430e8263e52a8ad650f98dbedc69954bc6650aff6675baf6ac73fcad18d663e",
                "MacAddress": "02:42:ac:11:00:02",
                "IPv4Address": "172.17.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]
[root@fastdfs network-scripts]#

进入docker容器内部

进入docker容器内部后如何退出

进入docker容器内部:

docker exec -it pensive_ishizaka /bin/bash

进入docker容器内部后如何退出

exit

eg:

[root@fastdfs ~]# docker exec -it pensive_ishizaka /bin/bash
root@5b8b0314c4dd:/opt/webapp# 
root@5b8b0314c4dd:/opt/webapp# ls
Procfile  app.py  requirements.txt  tests.py
root@5b8b0314c4dd:/opt/webapp# 
root@5b8b0314c4dd:/opt/webapp# exit
exit
[root@fastdfs ~]# 

 

参考:

Docker之常用命令 http://blog.chinaunix.net/uid-10915175-id-4443127.html

你可能感兴趣的:(docker)