ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

docker基础用法

2022-04-25 00:31:14  阅读:175  来源: 互联网

标签:24 httpd 容器 基础 用法 docker root localhost


什么是docker

docker中的容器:docker是一个管理容器的工具,程序。 

               lxc --> libcontainer --> runC

   

 

 

 

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 is a CLI tool for spawning and running containers according to the OCI specification

  • Containers are started as a child process of runC and can be embedded into various other systems without having to run a daemon
  • runC is built on libcontainer, the same container technology powering millions of Docker Engine installations

docker提供了一个专门容纳容器镜像的站点:https://hub.docker.com

runC是一个命令行工具包,用来创建和运行容器,根据OCI的标准。

包含以下两点:

1) 容器启动成runC的子进程,可以嵌入到其他各种系统中,而不需要运行守护进程

2) runC构建在libcontainer之上,同样的容器技术支撑着数以百万计的Docker Engine安装

docker提供了一个专门容纳容器镜像的站点:https://hub.docker.com

docker架构

 

 

 容器的服务需要设置开机自启,不然下次重启以后开机客户端访问服务端,服务端没启动,docker命令都是用不了

 docker -ee:企业版(收费的,还禁止亚洲人使用)

 docker-ce:社区版  (开源的,我们学习使用的都是这个版本)

 

docker镜像与镜像仓库

为什么镜像仓库名字是Registry而不是repository?在docker中仓库的名字是以应用的名称取名的。

 

 

Registry类似于是一个仓库的管理员,repository是存放镜像的仓库,每一个仓库存放着某一种镜像的各个版本,根据用户按需索取。

 镜像是静态的,而容器是动态的,容器有其生命周期,镜像与容器的关系类似于程序与进程的关系。镜像类似于文件系统中的程序文件,而容器则类似于将一个程序运行起来的状态,也即进程。所以容器是可以删除的,容器被删除后其镜像是不会被删除的。

docker对象

When you use docker, you are creating and using images, containers, networks, volumes, pluginns, and other objects.

  • IMAGES
    • An image is a read-only template with instructions for creating a docker container.
    • Often, an image is based on another image, with some additional customization.
    • You might create your own images or you might only use those created by others and published in a registry.
  • CONTAINERS
    • A conntainer is a runnable instance of an image.
    • You can create, run, stop, move, or delete a container using the docker API or CLI.
    • You can connect a container to one or more networks, attach storage to it, or even create a new image based on its current state.

当你使用docker时,你是在创建和使用镜像、容器、网络、卷、插件和其他对象。

 

镜像

镜像是一个只读模板,带有创建docker容器的说明。

通常,一个镜像基于另一个镜像,并带有一些额外的定制。

您可以创建自己的镜像,也可以只使用其他人创建并在注册表中发布的镜像。

容器

容器是运行中的镜像。

您可以使用docker API或CLI(敲命令)创建、运行、停止、移动或删除容器。

您可以将一个容器连接到一个或多个网络,将存储附加到它,甚至根据它的当前状态创建一个新镜像。

安装及使用docker

docker安装

 1 [root@localhost ~]# cd /etc/yum.repos.d/   进入源目录
 2 [root@localhost yum.repos.d]# ls
 3 CentOS-Stream-AppStream.repo  CentOS-Stream-Extras.repo            CentOS-Stream-NFV.repo         CentOS-Stream-ResilientStorage.repo
 4 CentOS-Stream-BaseOS.repo     CentOS-Stream-HighAvailability.repo  CentOS-Stream-PowerTools.repo  CentOS-Stream-Sources.repo
 5 CentOS-Stream-Debuginfo.repo  CentOS-Stream-Media.repo             CentOS-Stream-RealTime.repo
 6 [root@localhost yum.repos.d]# rm -rf *    首先把源都删除,配国内的源
 7 [root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
 8   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
 9                                  Dload  Upload   Total   Spent    Left  Speed
10 100  2495  100  2495    0     0  12053      0 --:--:-- --:--:-- --:--:-- 12053   配置阿里云的基础源
11 [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
12 [root@localhost yum.repos.d]# dnf clean all  清理缓存
13 21 文件已删除
14 [root@localhost yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm  配置epel源
15   [root@localhost ~]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
16   [root@localhost ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel
17 [root@localhost yum.repos.d]# dnf clean all   清理缓存
18 38 文件已删除
19 [root@localhost yum.repos.d]# dnf makecache  建立缓存
20 [root@localhost ~]# dnf -y install wget vim  安装wget vim
21 [root@localhost yum.repos.d]# wget  https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo    下载docker-ce文件
22 [root@localhost yum.repos.d]# ls
23 CentOS-Base.repo  docker-ce.repo  epel-modular.repo  epel.repo  epel-testing-modular.repo  epel-testing.repo  已下载
24 [root@localhost ~]# dnf makecache    建立缓存
25 [root@localhost ~]# dnf -y install docker-ce   安装docker-ce      一定不要忘记是docker-ce!!!

docker加速

docker-ce的配置文件是/etc/docker/daemon.json,此文件默认不存在,需要我们手动创建并进行配置,而docker的加速就是通过配置此文件来实现的。

docker的加速有多种方式:

  • docker cn(docker中国)
  • 中国科技大学加速器
  • 阿里云加速器(需要通过阿里云开发者平台注册帐号,免费使用个人私有的加速器)  我配置的aliyun加速器地址:www.aliyun.com
 1 [root@localhost ~]# systemctl enable --now docker
 2 Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.设为开机自启,立马启动,目录就创建出来了
 3 [root@localhost ~]# ls /etc/docker
 4 key.json     目录有了
 5 [root@localhost ~]# systemctl status docker   查看状态                   
 6 [root@localhost ~]# cd /etc/docker/  
 7 [root@localhost docker]# ls
 8 key.json
 9 [root@localhost docker]# vi daemon.json  用vi编辑器打开此文件配置
10     修改如下保存
11 {
12   "registry-mirrors": ["https://o8iex5ry.mirror.aliyuncs.com"]
13 }
14 [root@localhost docker]# systemctl daemon-reload重新加载一下
15 [root@localhost docker]# systemctl restart docker重启docker
16 [root@localhost docker]# docker info   查看主要信息
17 Client:  客户端
18  Context:    default  上下文是默认的
19  Debug Mode: false  Debug模式是默认没打开的
20  Plugins:               插件有:
21   app: Docker App (Docker Inc., v0.9.1-beta3)
22   buildx: Docker Buildx (Docker Inc., v0.8.1-docker)
23   scan: Docker Scan (Docker Inc., v0.17.0)
24 仓库在云上不在本机,客户端和服务端默认是在一起的
25 Server: 服务端
26  Containers: 0    容器0个
27   Running: 0      正在运行的0个
28   Paused: 0        暂停的0个
29   Stopped: 0      停止的0个
30  Images: 0        镜像有0个
31  Server Version: 20.10.14    版本
32  Storage Driver: overlay2     存储驱动
33   Backing Filesystem: xfs      后端存储驱动
34   Supports d_type: true
35   Native Overlay Diff: true
36   userxattr: false                用户属性
37  Logging Driver: json-file     日志驱动
38  Cgroup Driver: cgroupfs      控制组
39  Cgroup Version: 1                控制组的版本
40  Plugins:          插件
41   Volume: local      卷是在本地
42   Network: bridge host ipvlan macvlan null overlay 网络支持的模式
43   Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog   日志
44  Swarm: inactive     
45  Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc    运行时
46  Default Runtime: runc
47  Init Binary: docker-init    初始化的程序
48  containerd version: 3df54a852345ae127d1fa3092b95168e4a88e2f8  容器的版本号
49  runc version: v1.0.3-0-gf46b6ba    runc版本号
50  init version: de40ad0        初始化版本号
51  Security Options:        安全选项
52   seccomp                   
53    Profile: default
54  Kernel Version: 4.18.0-365.el8.x86_64    内核版本号
55  Operating System: CentOS Stream 8    操作系统
56  OSType: linux            系统类型
57  Architecture: x86_64    平台
58  CPUs: 4                       cpu
59  Total Memory: 1.744GiB    总共的内存
60  Name: localhost.localdomain   主机名
61  ID: IJYP:JJSC:VQ7M:JHVZ:IOCX:6DP3:ELBT:WADZ:KRZO:HP4Q:HC4B:QVAZ
62  Docker Root Dir: /var/lib/docker   docker家目录
63  Debug Mode: false
64  Registry: https://index.docker.io/v1/    仓库
65  Labels:      标签
66  Experimental: false
67  Insecure Registries:
68   127.0.0.0/8
69  Registry Mirrors: 看到此处就说明加速器配置成功
70   https://o8iex5ry.mirror.aliyuncs.com/
71  Live Restore Enabled: false

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

 

 1 [root@localhost ~]# ls /var/lib/docker    docker家目录
 2 buildkit  containers(容器)  image(镜像)  network  overlay2  plugins  runtimes  swarm  tmp  trust  volumes(卷)
 3 [root@localhost ~]# docker version    查看版本号
 4 Client: Docker Engine - Community  客户端的版本号
 5  Version:           20.10.14
 6  API version:       1.41
 7  Go version:        go1.16.15
 8  Git commit:        a224086
 9  Built:             Thu Mar 24 01:47:44 2022
10  OS/Arch:           linux/amd64
11  Context:           default
12  Experimental:      true
13 
14 Server: Docker Engine - Community     服务端的版本号
15  Engine:
16   Version:          20.10.14
17   API version:      1.41 (minimum version 1.12)
18   Go version:       go1.16.15
19   Git commit:       87a90dc
20   Built:            Thu Mar 24 01:46:10 2022
21   OS/Arch:          linux/amd64
22   Experimental:     false
23  containerd:
24   Version:          1.5.11
25   GitCommit:        3df54a852345ae127d1fa3092b95168e4a88e2f8
26  runc:
27   Version:          1.0.3
28   GitCommit:        v1.0.3-0-gf46b6ba
29  docker-init:
30   Version:          0.19.0
31   GitCommit:        de40ad0
32 [root@localhost ~]# docker search httpd  收索所有httpd的镜像 命令可以收索,网站也可以收索(信息更加详细)    如果拉镜像,前面有名字说明是私人做的,不要用,拉镜像的话就拉只有软件名字的,比如apache就只要只有httpd的,因为不安全,别人做的你也不知道里面有什么,你也不知道里面有没有病毒,选择官方的或者自己制作的。
33 NAME 镜像名字                              DESCRIPTION镜像描述                       STARS星数   OFFICIAL官方   AUTOMATED
34 httpd                                   The Apache HTTP Server Project                  3976      [OK]       
35 centos/httpd-24-centos7                 Platform for running Apache httpd 2.4 or bui…   44                   
36 centos/httpd                                                                            35                   [OK]
37 solsson/httpd-openidc                   mod_auth_openidc on official httpd image, ve…   2                    [OK]
38 hypoport/httpd-cgi                      httpd-cgi                                       2                    [OK]
39 dariko/httpd-rproxy-ldap                Apache httpd reverse proxy with LDAP authent…   1                    [OK]
40 manageiq/httpd                          Container with httpd, built on CentOS for Ma…   1                    [OK]
41 dockerpinata/httpd                                                                      1                    
42 publici/httpd                           httpd:latest                                    1                    [OK]
43 clearlinux/httpd                        httpd HyperText Transfer Protocol (HTTP) ser…   1                    
44 jonathanheilmann/httpd-alpine-rewrite   httpd:alpine with enabled mod_rewrite           1                    [OK]
45 inanimate/httpd-ssl                     A play container with httpd, ssl enabled, an…   1                    [OK]
46 centos/httpd-24-centos8                                                                 1                    
47 lead4good/httpd-fpm                     httpd server which connects via fcgi proxy h…   1                    [OK]
48 manageiq/httpd_configmap_generator      Httpd Configmap Generator                       0                    [OK]
49 e2eteam/httpd                                                                           0                    
50 paketobuildpacks/httpd                                                                  0                    
51 httpdocker/kubia-unhealthy                                                              0                    
52 httpdss/archerysec                      ArcherySec repository                           0                    [OK]
53 19022021/httpd-connection_test          This httpd image will test the connectivity …   0                    
54 patrickha/httpd-err                                                                     0                    
55 httpdocker/kubia                                                                        0                    
56 sandeep1988/httpd-new                   httpd-new                                       0                    
57 itsziget/httpd24                        Extended HTTPD Docker image based on the off…   0                    [OK]
58 manasip/httpd                                                                           0     
 1 [root@localhost ~]# docker pull httpd 拉镜像 没有跟版本号默认拉最新的
 2 Using default tag: latest
 3 latest: Pulling from library/httpd
 4 a2abf6c4d29d: Pull complete 
 5 dcc4698797c8: Pull complete 
 6 41c22baa66ec: Pull complete 
 7 67283bbdd4a0: Pull complete 
 8 d982c879c57e: Pull complete 
 9 Digest: sha256:0954cc1af252d824860b2c5dc0a10720af2b7a3d3435581ca788dff8480c7b32
10 Status: Downloaded newer image for httpd:latest
11 docker.io/library/httpd:latest
12 [root@localhost ~]#  docker pull httpd:2.4.53       拉指定版本的镜像
13 REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
14 httpd        2.4.53    c30a46771695   4 days ago     144MB
15 httpd        latest    dabbfbe0c57b   4 months ago   144MB
16 [root@localhost ~]# docker create --name web -p 80:80 httpd    创建一给叫web的容器,拉最新的httpd镜像,把容器的端口映射到真机  
17 97d2a3ef7bd5dec28489f601ca7d865d177abfc32899a2cdaf340c5bddb21df6  
18 [root@localhost ~]# docker ps    列出正在运行的容器
19 CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES   无
20 [root@localhost ~]# docker ps -a 列出容器
21 CONTAINER ID   IMAGE     COMMAND              CREATED         STATUS    PORTS     NAMES
22 97d2a3ef7bd5   httpd     "httpd-foreground"   3 minutes ago   Created             web
23 [root@localhost ~]# docker start web  启动叫web的容器也可以用id
24 web
25 [root@localhost ~]# docker ps  查看正在启动的容器
26 CONTAINER ID   IMAGE     COMMAND              CREATED         STATUS          PORTS                               NAMES
27 97d2a3ef7bd5   httpd     "httpd-foreground"   5 minutes ago   Up 38 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp   web
28 [root@localhost ~]# systemctl disable --now firewalld 关闭防火墙
29 Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
30 Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
31 [root@localhost ~]# vi /etc/selinux/config 关闭selinux
32 SELINUX=disabled   修改如下
33 [root@localhost ~]# setenforce 0 关完就可以访问

 

 

  1 [root@localhost ~]# docker ps 查看启动的容器
  2 CONTAINER ID   IMAGE     COMMAND              CREATED          STATUS          PORTS                               NAMES
  3 97d2a3ef7bd5   httpd     "httpd-foreground"   17 minutes ago   Up 13 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp   web
  4 [root@localhost ~]# docker stop web  停掉容器
  5 web
  6 [root@localhost ~]# docker ps -a  查看所有容器
  7 CONTAINER ID   IMAGE     COMMAND              CREATED          STATUS                     PORTS     NAMES
  8 97d2a3ef7bd5   httpd     "httpd-foreground"   18 minutes ago   Exited (0) 8 seconds ago             web   停止状态
  9 [root@localhost ~]# systemctl start firewalld  还得把防火墙打开才能启动,版本问题 .....
 10 [root@localhost ~]# docker start web   启动
 11 web
 12 [root@localhost ~]# ss -antl    查看端口号
 13 State             Recv-Q            Send-Q                       Local Address:Port                        Peer Address:Port            Process            
 14 LISTEN            0                 128                                0.0.0.0:22                               0.0.0.0:*                                  
 15 LISTEN            0                 128                                0.0.0.0:80                               0.0.0.0:*                                  
 16 LISTEN            0                 128                                   [::]:22                                  [::]:*                                  
 17 LISTEN            0                 128                                   [::]:80                                  [::]:*      
 18 [root@localhost ~]# firewall-cmd --add-rich-rule 'rule family=ipv4 source address=0.0.0.0/0 service name=http accept' --permanent 我们现在用的是默认端口号80,可以用放行协议来放行,如果不是默认就要放行端口号,
 19 success
 20 [root@localhost ~]# firewall-cmd --reload   从新加载一下
 21 success
 22 [root@localhost ~]# firewall-cmd --list-all  看一下富规则加进去没有
 23 public (active)
 24   target: default
 25   icmp-block-inversion: no
 26   interfaces: ens33
 27   sources: 
 28   services: cockpit dhcpv6-client ssh
 29   ports: 
 30   protocols: 
 31   forward: no
 32   masquerade: no
 33   forward-ports: 
 34   source-ports: 
 35   icmp-blocks: 
 36   rich rules:  富规则
 37     rule family="ipv4" source address="0.0.0.0/0" service name="http" accept
 38 [root@localhost ~]# docker restart web  重启
 39 web
 40 [root@localhost ~]# docker ps     5秒前启动的
 41 CONTAINER ID   IMAGE     COMMAND              CREATED          STATUS         PORTS                               NAMES
 42 97d2a3ef7bd5   httpd     "httpd-foreground"   53 minutes ago   Up 5 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp   web
 43 [root@localhost ~]# docker kill web   杀掉web容器
 44 web
 45 [root@localhost ~]# docker ps -a   56分钟前创建,现在退出了
 46 CONTAINER ID   IMAGE     COMMAND              CREATED          STATUS                        PORTS     NAMES
 47 97d2a3ef7bd5   httpd     "httpd-foreground"   56 minutes ago   Exited (137) 23 seconds ago             web
 48 [root@localhost ~]# docker logs web    查看日志
 49 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
 50 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
 51 [Sun Apr 24 14:54:25.312310 2022] [mpm_event:notice] [pid 1:tid 140244832513344] AH00489: Apache/2.4.52 (Unix) configured -- resuming normal operations
 52 [Sun Apr 24 14:54:25.312785 2022] [core:notice] [pid 1:tid 140244832513344] AH00094: Command line: 'httpd -D FOREGROUND'
 53 172.17.0.1 - - [24/Apr/2022:15:01:16 +0000] "GET / HTTP/1.1" 200 45
 54 172.17.0.1 - - [24/Apr/2022:15:02:07 +0000] "-" 408 -
 55 [Sun Apr 24 15:07:52.962964 2022] [mpm_event:notice] [pid 1:tid 140244832513344] AH00492: caught SIGWINCH, shutting down gracefully
 56 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
 57 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
 58 [Sun Apr 24 15:14:40.208384 2022] [mpm_event:notice] [pid 1:tid 140515652943168] AH00489: Apache/2.4.52 (Unix) configured -- resuming normal operations
 59 [Sun Apr 24 15:14:40.208950 2022] [core:notice] [pid 1:tid 140515652943168] AH00094: Command line: 'httpd -D FOREGROUND'
 60 192.168.149.1 - - [24/Apr/2022:15:41:34 +0000] "GET / HTTP/1.1" 304 -
 61 192.168.149.1 - - [24/Apr/2022:15:41:35 +0000] "GET / HTTP/1.1" 304 -
 62 192.168.149.1 - - [24/Apr/2022:15:41:36 +0000] "GET / HTTP/1.1" 304 -
 63 192.168.149.1 - - [24/Apr/2022:15:42:25 +0000] "-" 408 -
 64 [Sun Apr 24 15:42:51.711248 2022] [mpm_event:notice] [pid 1:tid 140515652943168] AH00492: caught SIGWINCH, shutting down gracefully
 65 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
 66 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
 67 [Sun Apr 24 15:42:53.991580 2022] [mpm_event:notice] [pid 1:tid 140464370867520] AH00489: Apache/2.4.52 (Unix) configured -- resuming normal operations
 68 [Sun Apr 24 15:42:53.991784 2022] [core:notice] [pid 1:tid 140464370867520] AH00094: Command line: 'httpd -D FOREGROUND'
 69 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
 70 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
 71 [Sun Apr 24 15:47:58.677655 2022] [mpm_event:notice] [pid 1:tid 140279530904896] AH00489: Apache/2.4.52 (Unix) configured -- resuming normal operations
 72 [Sun Apr 24 15:47:58.678076 2022] [core:notice] [pid 1:tid 140279530904896] AH00094: Command line: 'httpd -D FOREGROUND'
 73 192.168.149.1 - - [24/Apr/2022:15:48:26 +0000] "GET / HTTP/1.1" 304 -
 74 192.168.149.1 - - [24/Apr/2022:15:48:27 +0000] "GET / HTTP/1.1" 304 -
 75 192.168.149.1 - - [24/Apr/2022:15:48:27 +0000] "GET / HTTP/1.1" 304 -
 76 192.168.149.1 - - [24/Apr/2022:15:48:28 +0000] "GET / HTTP/1.1" 304 -
 77 192.168.149.1 - - [24/Apr/2022:15:48:29 +0000] "GET / HTTP/1.1" 304 -
 78 [root@localhost ~]# docker rm -f web  强制删除web容器
 79 web
 80 [root@localhost ~]# docker ps  
 81 CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
 82 [root@localhost ~]# docker images   容器删了镜像还在
 83 REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
 84 httpd        2.4.53    c30a46771695   4 days ago     144MB
 85 httpd        latest    dabbfbe0c57b   4 months ago   144MB
 86 [root@localhost ~]# docker run -it --name test busybox /bin/sh    在交互模式下启动使用busybox镜像叫test的容器并且进到它的/bin/sh里去    
 87 Unable to find image 'busybox:latest' locally     docker run可以一部到位让容器运行起来并且进到容器
 88 latest: Pulling from library/busybox
 89 5cc84ad355aa: Pull complete 
 90 Digest: sha256:5acba83a746c7608ed544dc1533b87c737a0b0fb730301639a0179f9344b1678
 91 Status: Downloaded newer image for busybox:latest
 92 / # exit   容器就会停掉不是删除,
 93 [root@localhost ~]# docker start test   可以再次启动
 94 test
 95 [root@localhost ~]# docker ps
 96 CONTAINER ID   IMAGE     COMMAND     CREATED         STATUS          PORTS     NAMES
 97 54c784b3770e   busybox   "/bin/sh"   9 minutes ago   Up 10 seconds             test
 98 [root@localhost ~]# docker attach  test   进到容器里面
 99 / # exit  退出会停掉
100 
101 
102 [root@localhost ~]# docker ps
103 CONTAINER ID   IMAGE     COMMAND     CREATED          STATUS          PORTS     NAMES
104 54c784b3770e   busybox   "/bin/sh"   17 minutes ago   Up 17 seconds             test
105 [root@localhost ~]#docker exec -it test /bin/sh这种方式推出不会停
106 / # exit
107 [root@localhost ~]# docker ps
108 CONTAINER ID   IMAGE     COMMAND     CREATED          STATUS              PORTS     NAMES
109 54c784b3770e   busybox   "/bin/sh"   18 minutes ago   Up About a minute             test
110 
111 
112   

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

标签:24,httpd,容器,基础,用法,docker,root,localhost
来源: https://www.cnblogs.com/sunyiming023654/p/16188455.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有