什么是docker
docker中的容器:
- lxc --> libcontainer --> runC
OCI&OCF
OCI
Open Container-initiative (开放的容器规范)
- 由Linux基金会主导于2015年6月创立
- 旨在围绕容器格式和运行时制定一个开放的工业化标准
- contains two specifications
- the Runtime Specification(runtime-spec)
- the Image Specification(image-spec)
OCF
Open Container Format (开放的容器格式)
runC是一个命令行工具,用于根据OCI规范来创建和运行容器
- 容器作为runC的子进程启动,可以嵌入到其他各种系统中,而不需要运行守护进程
- runC构建在libcontainer之上,同样的容器技术支撑着数以百万计的Docker Engine安装
docker提供了一个专门容纳容器镜像的站点:https://hub.docker.com
docker架构
docker镜像与镜像仓库
为什么镜像仓库名字是Registry而不是repository?在docker中仓库的名字是以应用的名称取名的。
镜像是静态的,而容器是动态的,容器有其生命周期,镜像与容器的关系类似于程序与进程的关系。镜像类似于文件系统中的程序文件,而容器则类似于将一个程序运行起来的状态,也即进程。所以容器是可以删除的,容器被删除后其镜像是不会被删除的。
docker对象
当你使用docker时,你是在创建和使用图像、容器、网络、卷、插件和其他对象。
- IMAGES (镜像)
- 镜像是一个只读模板,带有创建docker容器的说明。
- 通常,一个镜像基于另一个镜像,并带有一些额外的定制。
- 您可以创建自己的镜像,也可以只使用其他人创建并在注册表中发布的镜像。
- CONTAINERS (容器)
- 容器是一个运行中的镜像。
- 您可以使用docker 的API或CLI创建、运行、停止、移动或删除容器。
- 您可以将一个容器连接到一个或多个网络,将存储附加到它,甚至根据它的当前状态创建一个新镜像。
安装及使用docker
docker安装
配置yum源
地址:https://developer.aliyun.com/mirror/
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
redhat.repo
[root@localhost yum.repos.d]# rm -rf *
[root@localhost yum.repos.d]# ls
[root@localhost yum.repos.d]# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.5 (Ootpa)
[root@localhost yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2495 100 2495 0 0 5144 0 --:--:-- --:--:-- --:--:-- 5133
[root@localhost yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@localhost yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@localhost yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@localhost yum.repos.d]# yum clean all //清除缓存
18 files removed
[root@localhost yum.repos.d]# dnf makecahce //建立缓存
配置docker源
地址 :https://mirrors.aliyun.com/docker-ce/
[root@localhost ~]# dnf -y install vim wget
[root@localhost yum.repos.d]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost yum.repos.d]# ls
CentOS-Base.repo docker-ce.repo epel-modular.repo epel.repo epel-testing-modular.repo epel-testing.repo redhat.repo
[root@localhost ~]# dnf makecache
安装docker
[root@localhost ~]# dnf list all|grep docker //过滤
containerd.io.x86_64 1.5.11-3.1.el8 docke-ce-stable
docker-ce.x86_64 3:20.10.14-3.el8 docke-ce-stable
docker-ce-cli.x86_64 1:20.10.14-3.el8 docke-ce-stable
docker-ce-rootless-extras.x86_64 20.10.14-3.el8 docke-ce-stable
docker-compose-plugin.x86_64 2.3.3-3.el8 docke-ce-stable
docker-scan-plugin.x86_64 0.17.0-3.el8 docke-ce-stable
pcp-pmda-docker.x86_64 5.3.1-5.el8 AppStream
podman-docker.noarch 3.3.1-9.module_el8.5.0+988+b1f0b741 AppStream
python-docker-tests.noarch 5.0.0-2.el8 epel
python2-dockerpty.noarch 0.4.1-18.el8 epel
python3-docker.noarch 5.0.0-2.el8 epel
python3-dockerpty.noarch 0.4.1-18.el8 epel
standard-test-roles-inventory-docker.noarch 4.10-1.el8 epel
[root@localhost ~]# dnf -y install docker-ce
docker加速
docker-ce的配置文件是/etc/docker/daemon.json,此文件默认不存在,需要我们手动创建并进行配置,而docker的加速就是通过配置此文件来实现的。
docker的加速有多种方式:
- docker cn
- 中国科技大学加速器
- 阿里云加速器(需要通过阿里云开发者平台注册帐号,免费使用个人私有的加速器)
[root@localhost ~]# ls /etc/docker //默认是没有这个目录的
ls: cannot access '/etc/docker': No such file or directory
[root@localhost ~]# systemctl enable --now docker //设置为开机自启
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
[root@localhost ~]# systemctl status docker //查看状态
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2022-04-24 17:44:03 CST; 1min 8s ago
Docs: https://docs.docker.com
Main PID: 13094 (dockerd)
Tasks: 8
Memory: 30.4M
CGroup: /system.slice/docker.service
└─13094 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Apr 24 17:44:02 localhost.localdomain dockerd[13094]: time="2022-04-24T17:44:02.232871651+08:00" level=warning msg="Your kerne>
Apr 24 17:44:02 localhost.localdomain dockerd[13094]: time="2022-04-24T17:44:02.232924319+08:00" level=warning msg="Your kerne>
Apr 24 17:44:02 localhost.localdomain dockerd[13094]: time="2022-04-24T17:44:02.233132619+08:00" level=info msg="Loading conta>
Apr 24 17:44:03 localhost.localdomain dockerd[13094]: time="2022-04-24T17:44:03.049223643+08:00" level=info msg="Default bridg>
Apr 24 17:44:03 localhost.localdomain dockerd[13094]: time="2022-04-24T17:44:03.158757652+08:00" level=info msg="Firewalld: in>
Apr 24 17:44:03 localhost.localdomain dockerd[13094]: time="2022-04-24T17:44:03.278197064+08:00" level=info msg="Loading conta>
Apr 24 17:44:03 localhost.localdomain dockerd[13094]: time="2022-04-24T17:44:03.295548571+08:00" level=info msg="Docker daemon>
Apr 24 17:44:03 localhost.localdomain dockerd[13094]: time="2022-04-24T17:44:03.295731864+08:00" level=info msg="Daemon has co>
Apr 24 17:44:03 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
Apr 24 17:44:03 localhost.localdomain dockerd[13094]: time="2022-04-24T17:44:03.319648356+08:00" level=info msg="API listen on>
[root@localhost ~]# ls /etc/docker //启动会自动创建目录
key.json
配置镜像加速器
[root@localhost ~]# cd /etc/docker
[root@localhost docker]# ls
key.json
[root@localhost docker]# vim daemon.json
[root@localhost docker]# cat daemon.json
{
"registry-mirrors": ["https://bxrtqrie.mirror.aliyuncs.com"]
}
[root@localhost docker]# systemctl daemon-reload
[root@localhost docker]# systemctl restart docker
[root@localhost docker]# systemctl daemon-reload //重新加载
[root@localhost docker]# systemctl restart docker //重启
列出docker运行的环境
[root@localhost ~]# docker info
Client: //客户端
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Docker Buildx (Docker Inc., v0.8.1-docker)
scan: Docker Scan (Docker Inc., v0.17.0)
Server: //服务端
Containers: 0 //容器
Running: 0 //正在运行的
Paused: 0 //暂停的
Stopped: 0 //停止的
Images: 0 //镜像
Server Version: 20.10.14
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins: //插件
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 3df54a852345ae127d1fa3092b95168e4a88e2f8
runc version: v1.0.3-0-gf46b6ba
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 4.18.0-348.el8.x86_64
Operating System: Red Hat Enterprise Linux 8.5 (Ootpa)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.748GiB
Name: localhost.localdomain
ID: ZD2F:B7WG:3J7K:NFXG:WALF:KDP3:XYB7:PP2C:I5YR:PMTB:X7MM:STJE
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://bxrtqrie.mirror.aliyuncs.com/ //看到这个表示配置成功
Live Restore Enabled: false
查看版本号
[root@localhost ~]# docker version
Client: Docker Engine - Community
Version: 20.10.14
API version: 1.41
Go version: go1.16.15
Git commit: a224086
Built: Thu Mar 24 01:47:44 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.14
API version: 1.41 (minimum version 1.12)
Go version: go1.16.15
Git commit: 87a90dc
Built: Thu Mar 24 01:46:10 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.5.11
GitCommit: 3df54a852345ae127d1fa3092b95168e4a88e2f8
runc:
Version: 1.0.3
GitCommit: v1.0.3-0-gf46b6ba
docker-init:
Version: 0.19.0
GitCommit: de40ad0
docker常用操作
命令 | 功能 |
---|---|
docker search | Search the Docker Hub for images |
docker pull | Pull an image or a repository from a registry |
docker images | List images |
docker create | Create a new conntainer |
docker start | Start one or more stopped containers |
docker run | Run a command in a new container |
docker attach | Attach to a runninng container |
docker ps | List containers |
docker logs | Fetch the logs of a container |
docker restart | Restart a container |
docker stop | Stop one or more running containers |
docker kill | Kill one or more running containers |
docker rm | Remove onne or more containers |
docker exec | Run a command in a running container |
docker info | Display system-wide information |
docker inspect | Return low-level information on Docker objects |
[root@localhost ~]# docker search httpd //搜索httpd镜像
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
httpd The Apache HTTP Server Project 3976 [OK]
centos/httpd-24-centos7 Platform for running Apache httpd 2.4 or bui… 44
centos/httpd 35 [OK]
solsson/httpd-openidc mod_auth_openidc on official httpd image, ve… 2 [OK]
hypoport/httpd-cgi httpd-cgi 2 [OK]
dariko/httpd-rproxy-ldap Apache httpd reverse proxy with LDAP authent… 1 [OK]
manageiq/httpd Container with httpd, built on CentOS for Ma… 1 [OK]
dockerpinata/httpd 1
publici/httpd httpd:latest 1 [OK]
clearlinux/httpd httpd HyperText Transfer Protocol (HTTP) ser… 1
jonathanheilmann/httpd-alpine-rewrite httpd:alpine with enabled mod_rewrite 1 [OK]
inanimate/httpd-ssl A play container with httpd, ssl enabled, an… 1 [OK]
centos/httpd-24-centos8 1
lead4good/httpd-fpm httpd server which connects via fcgi proxy h… 1 [OK]
manageiq/httpd_configmap_generator Httpd Configmap Generator 0 [OK]
e2eteam/httpd 0
paketobuildpacks/httpd 0
httpdocker/kubia-unhealthy 0
manasip/httpd 0
19022021/httpd-connection_test This httpd image will test the connectivity … 0
patrickha/httpd-err 0
httpdocker/kubia 0
sandeep1988/httpd-new httpd-new 0
itsziget/httpd24 Extended HTTPD Docker image based on the off… 0 [OK]
httpdss/archerysec ArcherySec repository 0 [OK]
列出
[root@localhost ~]# docker images //列出所有镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
镜像仓库 版本 id 创建 大小
从镜像仓库中拉取镜像
[root@localhost ~]# docker pull httpd //拉取镜像,默认下载最新版本
Using default tag: latest
latest: Pulling from library/httpd
a2abf6c4d29d: Pull complete
dcc4698797c8: Pull complete
41c22baa66ec: Pull complete
67283bbdd4a0: Pull complete
d982c879c57e: Pull complete
Digest: sha256:0954cc1af252d824860b2c5dc0a10720af2b7a3d3435581ca788dff8480c7b32
Status: Downloaded newer image for httpd:latest
docker.io/library/httpd:latest
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest dabbfbe0c57b 4 months ago 144MB
[root@localhost ~]# docker pull httpd:2.4.53 //指定拉取镜像版本
2.4.53: Pulling from library/httpd
1fe172e4850f: Pull complete
e2fa1fe9b1ec: Pull complete
60dd7398e74e: Pull complete
ea2ca81c6d4c: Pull complete
f646c69a26ec: Pull complete
Digest: sha256:e02a2ef36151905c790efb0a8472f690010150f062639bd8c0760e7b1e884c07
Status: Downloaded newer image for httpd:2.4.53
docker.io/library/httpd:2.4.53
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd 2.4.53 c30a46771695 4 days ago 144MB
httpd latest dabbfbe0c57b 4 months ago 144MB
创建容器
[root@localhost ~]# docker create --name web -p 80:80 httpd //创建容器
8a72caa3468adf84049fecd72875f3a2c183c1aff397d608d8f03b3df0e4d305
[root@localhost ~]# docker ps //列出正在运行的容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@localhost ~]# docker ps -a //查看所有容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8a72caa3468a httpd "httpd-foreground" About a minute ago Created web
[root@localhost ~]# docker start web //运行容器
web
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8a72caa3468a httpd "httpd-foreground" 2 minutes ago Up 9 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp web
[root@localhost ~]# systemctl disable --now firewalld //关闭防火墙
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled //修改此行
[root@localhost ~]# setenforce 0
停止容器
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8a72caa3468a httpd "httpd-foreground" 7 minutes ago Up 5 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp web
[root@localhost ~]# docker stop 8a72caa3468a //用id停止容器
8a72caa3468a
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
重新启动容器
[root@localhost ~]# systemctl start --now firewalld //打开防火墙
[root@localhost ~]# docker start web //运行容器
web
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8a72caa3468a httpd "httpd-foreground" 11 minutes ago Up 6 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp web
[root@localhost ~]# docker restart web //重新启动
web
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8a72caa3468a httpd "httpd-foreground" 20 minutes ago Up 4 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp web
防火墙放行
[root@localhost ~]# firewall-cmd --add-rich-rule 'rule family=ipv4 source address=0.0.0.0/0 service name=http accept' --permanent //富规则
success
[root@localhost ~]# firewall-cmd --reload //重新加载
success
[root@localhost ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens160
sources:
services: cockpit dhcpv6-client ssh
ports:
protocols:
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
rule family="ipv4" source address="0.0.0.0/0" service name="http" accept
杀掉容器
[root@localhost ~]# docker kill web // stop正常退出 kill强制关闭
web
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
查看日志
[root@localhost ~]# docker logs web
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[Sun Apr 24 11:22:38.318476 2022] [mpm_event:notice] [pid 1:tid 140111177428288] AH00489: Apache/2.4.52 (Unix) configured -- resuming normal operations
[Sun Apr 24 11:22:38.318748 2022] [core:notice] [pid 1:tid 140111177428288] AH00094: Command line: 'httpd -D FOREGROUND'
172.17.0.1 - - [24/Apr/2022:11:26:51 +0000] "GET / HTTP/1.1" 200 45
172.17.0.1 - - [24/Apr/2022:11:26:54 +0000] "GET /favicon.ico HTTP/1.1" 404 196
172.17.0.1 - - [24/Apr/2022:11:27:46 +0000] "-" 408 -
[Sun Apr 24 11:28:44.838964 2022] [mpm_event:notice] [pid 1:tid 140111177428288] AH00492: caught SIGWINCH, shutting down gracefully
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[Sun Apr 24 11:31:54.183400 2022] [mpm_event:notice] [pid 1:tid 140595145936192] AH00489: Apache/2.4.52 (Unix) configured -- resuming normal operations
[Sun Apr 24 11:31:54.183585 2022] [core:notice] [pid 1:tid 140595145936192] AH00094: Command line: 'httpd -D FOREGROUND'
192.168.50.1 - - [24/Apr/2022:11:32:41 +0000] "GET / HTTP/1.1" 304 -
192.168.50.1 - - [24/Apr/2022:11:32:42 +0000] "GET / HTTP/1.1" 304 -
192.168.50.1 - - [24/Apr/2022:11:32:43 +0000] "GET / HTTP/1.1" 304 -
192.168.50.1 - - [24/Apr/2022:11:32:44 +0000] "GET / HTTP/1.1" 304 -
192.168.50.1 - - [24/Apr/2022:11:32:44 +0000] "GET / HTTP/1.1" 304 -
192.168.50.1 - - [24/Apr/2022:11:32:45 +0000] "GET / HTTP/1.1" 304 -
192.168.50.1 - - [24/Apr/2022:11:32:45 +0000] "GET / HTTP/1.1" 304 -
192.168.50.1 - - [24/Apr/2022:11:32:45 +0000] "GET / HTTP/1.1" 304 -
192.168.50.1 - - [24/Apr/2022:11:32:48 +0000] "GET / HTTP/1.1" 304 -
192.168.50.1 - - [24/Apr/2022:11:33:33 +0000] "-" 408 -
192.168.50.1 - - [24/Apr/2022:11:37:06 +0000] "-" 408 -
192.168.50.1 - - [24/Apr/2022:11:37:06 +0000] "-" 408 -
[Sun Apr 24 11:41:00.972713 2022] [mpm_event:notice] [pid 1:tid 140595145936192] AH00492: caught SIGWINCH, shutting down gracefully
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[Sun Apr 24 11:41:02.595618 2022] [mpm_event:notice] [pid 1:tid 139810815487296] AH00489: Apache/2.4.52 (Unix) configured -- resuming normal operations
[Sun Apr 24 11:41:02.595727 2022] [core:notice] [pid 1:tid 139810815487296] AH00094: Command line: 'httpd -D FOREGROUND'
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[Sun Apr 24 11:45:21.838953 2022] [mpm_event:notice] [pid 1:tid 139953692400960] AH00489: Apache/2.4.52 (Unix) configured -- resuming normal operations
[Sun Apr 24 11:45:21.839195 2022] [core:notice] [pid 1:tid 139953692400960] AH00094: Command line: 'httpd -D FOREGROUND'
192.168.50.1 - - [24/Apr/2022:11:45:37 +0000] "GET / HTTP/1.1" 304 -
192.168.50.1 - - [24/Apr/2022:11:45:39 +0000] "GET / HTTP/1.1" 304 -
删除容器,可以删除一个或多个,但不能删除正在运行的容器
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8a72caa3468a httpd "httpd-foreground" 32 minutes ago Up 8 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp web
[root@localhost ~]# docker rm -f 8a72caa3468a //-f强制删除正在运行的容器
8a72caa3468a
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
从镜像仓库拉取busybox创建一个容器
[root@localhost ~]# docker run -it --name yyqx busybox /bin/sh //it交互模式
Unable to find image 'busybox:latest' locally
latest: Pulling from library/busybox
5cc84ad355aa: Pull complete
Digest: sha256:5acba83a746c7608ed544dc1533b87c737a0b0fb730301639a0179f9344b1678
Status: Downloaded newer image for busybox:latest
/ # ip a //进入容器里面,查看容器ip
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
14: eth0@if15: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
/ # exit //退出后容器停止了
[root@localhost ~]# docker start yyqx //启动后默认进不去
yyqx
[root@localhost ~]# docker attach yyqx //进去以后退出默认停止容器
/ # exit
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
86e83715dda9 busybox "/bin/sh" 5 minutes ago Exited (0) 6 seconds ago yyqx
[root@localhost ~]# docker start yyqx
yyqx
[root@localhost ~]# docker exec -it yyqx /bin/sh //退出后,容器还在运行
/ # exit
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
86e83715dda9 busybox "/bin/sh" 7 minutes ago Up 40 seconds yyqx