Docker集群

发布于:2019-1-30 15:28 作者:admin 浏览:2646 分类:系统架构
[root@localhost docker]# docker swarm init
Swarm initialized: current node (vgc6172h94lo7vktpxs9hnb1y) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join \
    --token SWMTKN-1-0dpoajwlnlig2pvbujiqzogodwilx6fezg7rgpjfsvob49vnzl-1lq8jjz0hqvcmd2ay91ornac6 \
    192.168.100.136:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.


[root@localhost docker]# docker node ls
ID                           HOSTNAME               STATUS  AVAILABILITY  MANAGER STATUS
vgc6172h94lo7vktpxs9hnb1y *  localhost.localdomain  Ready   Active        Leader


[root@localhost docker]# docker service create --name nginx --publish 80:80 --replicas 3 docker.io/idiswy/lnmp
td9afve2mqcs4l6t0w4dro8ve

[root@localhost docker]# docker service ls
ID            NAME   MODE        REPLICAS  IMAGE
td9afve2mqcs  nginx  replicated  3/3       docker.io/idiswy/lnmp:latest

[root@localhost docker]# docker service ps nginx
ID            NAME     IMAGE                         NODE                   DESIRED STATE  CURRENT STATE               ERROR  PORTS
tnwlid5v447j  nginx.1  docker.io/idiswy/lnmp:latest  localhost.localdomain  Running        Running about a minute ago         
f1h4cenjlj06  nginx.2  docker.io/idiswy/lnmp:latest  localhost.localdomain  Running        Running about a minute ago         
k6m7nqosffna  nginx.3  docker.io/idiswy/lnmp:latest  localhost.localdomain  Running        Running about a minute ago    

[root@localhost docker]# docker service scale nginx=6
nginx scaled to 6

[root@localhost docker]# docker service ps nginx
ID            NAME     IMAGE                         NODE                   DESIRED STATE  CURRENT STATE           ERROR  PORTS
tnwlid5v447j  nginx.1  docker.io/idiswy/lnmp:latest  localhost.localdomain  Running        Running 2 minutes ago          
f1h4cenjlj06  nginx.2  docker.io/idiswy/lnmp:latest  localhost.localdomain  Running        Running 2 minutes ago          
k6m7nqosffna  nginx.3  docker.io/idiswy/lnmp:latest  localhost.localdomain  Running        Running 2 minutes ago          
mxx8konbil7u  nginx.4  docker.io/idiswy/lnmp:latest  localhost.localdomain  Running        Running 20 seconds ago         
v6hw4wkm1mf5  nginx.5  docker.io/idiswy/lnmp:latest  localhost.localdomain  Running        Running 20 seconds ago         
7mjvtqhxdiqm  nginx.6  docker.io/idiswy/lnmp:latest  localhost.localdomain  Running        Running 20 seconds ago      


[root@localhost docker]# docker ps
CONTAINER ID        IMAGE                                                                                           COMMAND             CREATED              STATUS              PORTS               NAMES
25eb9d5a1a49        docker.io/idiswy/lnmp@sha256:ddb256e6834e5bd0dbaa0d9130ff94312ecdb1ae19669cc747e99620c4edd656   "/sbin/my_init"     About a minute ago   Up About a minute   80/tcp, 443/tcp     nginx.5.v6hw4wkm1mf5cjvf82vet2f4w
0a1654460e59        docker.io/idiswy/lnmp@sha256:ddb256e6834e5bd0dbaa0d9130ff94312ecdb1ae19669cc747e99620c4edd656   "/sbin/my_init"     About a minute ago   Up About a minute   80/tcp, 443/tcp     nginx.6.7mjvtqhxdiqm3bxwqmeepo0sh
ecba5be3df16        docker.io/idiswy/lnmp@sha256:ddb256e6834e5bd0dbaa0d9130ff94312ecdb1ae19669cc747e99620c4edd656   "/sbin/my_init"     About a minute ago   Up About a minute   80/tcp, 443/tcp     nginx.4.mxx8konbil7uq0c9kydos5hei
148735b9e91b        docker.io/idiswy/lnmp@sha256:ddb256e6834e5bd0dbaa0d9130ff94312ecdb1ae19669cc747e99620c4edd656   "/sbin/my_init"     3 minutes ago        Up 3 minutes        80/tcp, 443/tcp     nginx.2.f1h4cenjlj064nfmkyddufze0
dafd4c20c955        docker.io/idiswy/lnmp@sha256:ddb256e6834e5bd0dbaa0d9130ff94312ecdb1ae19669cc747e99620c4edd656   "/sbin/my_init"     3 minutes ago        Up 3 minutes        80/tcp, 443/tcp     nginx.3.k6m7nqosffnayodp1qjph7o02
020f1099d809        docker.io/idiswy/lnmp@sha256:ddb256e6834e5bd0dbaa0d9130ff94312ecdb1ae19669cc747e99620c4edd656   "/sbin/my_init"     3 minutes ago        Up 3 minutes        80/tcp, 443/tcp     nginx.1.tnwlid5v447jl61kh8ukg8eob


标签: Docker

0

CentOS构建Docker2

发布于:2019-1-30 9:03 作者:admin 浏览:2475 分类:系统架构
查看版本
[root@localhost ~]# docker version
Client:
 Version:         1.13.1
 API version:     1.26
 Package version: docker-1.13.1-88.git07f3374.el7.centos.x86_64
 Go version:      go1.9.4
 Git commit:      07f3374/1.13.1
 Built:           Fri Dec  7 16:13:51 2018
 OS/Arch:         linux/amd64

Server:
 Version:         1.13.1
 API version:     1.26 (minimum version 1.12)
 Package version: docker-1.13.1-88.git07f3374.el7.centos.x86_64
 Go version:      go1.9.4
 Git commit:      07f3374/1.13.1
 Built:           Fri Dec  7 16:13:51 2018
 OS/Arch:         linux/amd64
 Experimental:    false


搜索容器镜像
[root@localhost ~]# docker search centos
INDEX       NAME                                         DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/centos                             The official build of CentOS.                   5147      [OK]       
docker.io   docker.io/ansible/centos7-ansible            Ansible on Centos7                              119                  [OK]
docker.io   docker.io/jdeathe/centos-ssh                 CentOS-6 6.10 x86_64 / CentOS-7 7.5.1804 x...   106                  [OK]
docker.io   docker.io/consol/centos-xfce-vnc             Centos container with "headless" VNC sessi...   78                   [OK]
docker.io   docker.io/imagine10255/centos6-lnmp-php56    centos6-lnmp-php56                              50                   [OK]
docker.io   docker.io/centos/mysql-57-centos7            MySQL 5.7 SQL database server                   45                   
docker.io   docker.io/tutum/centos                       Simple CentOS docker image with SSH access      43                   
docker.io   docker.io/openshift/base-centos7             A Centos7 derived base image for Source-To...   39                   
docker.io   docker.io/gluster/gluster-centos             Official GlusterFS Image [ CentOS-7 +  Glu...   38                   [OK]
docker.io   docker.io/centos/postgresql-96-centos7       PostgreSQL is an advanced Object-Relationa...   37                   
docker.io   docker.io/centos/python-35-centos7           Platform for building and running Python 3...   33                   
docker.io   docker.io/kinogmt/centos-ssh                 CentOS with SSH                                 25                   [OK]
docker.io   docker.io/openshift/jenkins-2-centos7        A Centos7 based Jenkins v2.x image for use...   20                   
docker.io   docker.io/centos/php-56-centos7              Platform for building and running PHP 5.6 ...   19                   
docker.io   docker.io/pivotaldata/centos-gpdb-dev        CentOS image for GPDB development. Tag nam...   10                   
docker.io   docker.io/openshift/wildfly-101-centos7      A Centos7 based WildFly v10.1 image for us...   6                    
docker.io   docker.io/openshift/jenkins-1-centos7        DEPRECATED: A Centos7 based Jenkins v1.x i...   4                    
docker.io   docker.io/darksheer/centos                   Base Centos Image -- Updated hourly             3                    [OK]
docker.io   docker.io/pivotaldata/centos                 Base centos, freshened up a little with a ...   2                    
docker.io   docker.io/pivotaldata/centos-mingw           Using the mingw toolchain to cross-compile...   2                    
docker.io   docker.io/blacklabelops/centos               CentOS Base Image! Built and Updates Daily!     1                    [OK]
docker.io   docker.io/pivotaldata/centos-gcc-toolchain   CentOS with a toolchain, but unaffiliated ...   1                    
docker.io   docker.io/pivotaldata/centos7-build          CentosOS 7 image for GPDB compilation           0                    
docker.io   docker.io/pivotaldata/centos7-test           CentosOS 7 image for GPDB testing               0                    
docker.io   docker.io/smartentry/centos                  centos with smartentry                          0                    [OK]



下载容器镜像
[root@localhost ~]# docker pull docker.io/centos
Using default tag: latest
Trying to pull repository docker.io/library/centos ... 
latest: Pulling from docker.io/library/centos
5e6ec7f28fb7: Pull complete 
566e675a8212: Pull complete 
ef5a8026039b: Pull complete 
22ecb0106557: Pull complete 
91cc511c603e: Pull complete 
Digest: sha256:184e5f35598e333bfa7de10d8fb1cebb5ee4df5bc0f970bf2b1e7c7345136426
Status: Downloaded newer image for docker.io/centos:latest


查看容器镜像
[root@localhost ~]# docker images centos
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/centos    latest              1e1148e4cc2c        7 weeks ago         202 MB

运行容器镜像
[root@localhost ~]# docker run centos  echo "Hello Centos"
Hello Centos


命令行运行容器镜像
[root@localhost ~]# docker run -t -i centos /bin/bash
[root@4bf88ec1e25e /]# echo "Hello Centos"
Hello Centos

保存对容器的修改
[root@localhost ~]# docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS                     PORTS               NAMES
4bf88ec1e25e        centos              "/bin/bash"         About a minute ago   Exited (0) 5 seconds ago                       mystifying_kilby
[root@localhost ~]# docker commit -m="Hello Centos"  4bf88ec1e25e  hellocentos
sha256:05c7c5c8c6f1ef66736cd1c6256cdd94629263ff67375e78e040e34dce2fb548

检查运行中的镜像
[root@localhost ~]# docker run hellocentos echo "Hello Centos"
WARNING: IPv4 forwarding is disabled. Networking will not work.
Hello Centos
[root@localhost ~]# docker inspect hellocentos
[
    {
        "Id": "sha256:05c7c5c8c6f1ef66736cd1c6256cdd94629263ff67375e78e040e34dce2fb548",
        "RepoTags": [
            "hellocentos:latest"
        ],
        "RepoDigests": [],
        "Parent": "sha256:1e1148e4cc2c148c6890a18e3b2d2dde41a6745ceb4e5fe94a923d811bf82ddb",
        "Comment": "Hello Centos",
        "Created": "2019-01-29T02:15:06.601658579Z",
        "Container": "4bf88ec1e25ebb0b91dd80fce5e26138c8f955f4edeb6c778422af65a66c7b6d",
        "ContainerConfig": {
            "Hostname": "4bf88ec1e25e",
            "Domainname": "",
            "User": "",
            "AttachStdin": true,
            "AttachStdout": true,
            "AttachStderr": true,
            "Tty": true,
            "OpenStdin": true,
            "StdinOnce": true,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/bash"
            ],
            "Image": "centos",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "org.label-schema.build-date": "20181205",
                "org.label-schema.license": "GPLv2",
                "org.label-schema.name": "CentOS Base Image",
                "org.label-schema.schema-version": "1.0",
                "org.label-schema.vendor": "CentOS"
            }
        },
        "DockerVersion": "1.13.1",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/bash"
            ],
            "Image": "",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "org.label-schema.build-date": "20181205",
                "org.label-schema.license": "GPLv2",
                "org.label-schema.name": "CentOS Base Image",
                "org.label-schema.schema-version": "1.0",
                "org.label-schema.vendor": "CentOS"
            }
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 201779629,
        "VirtualSize": 201779629,
        "GraphDriver": {
            "Name": "overlay2",
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/2e17ffe2a2acae3ca7b05851e5b2a8f4858bdec98b9ffeddaff1416851167d83/diff",
                "MergedDir": "/var/lib/docker/overlay2/6cbdbc6d1560ec1fe0b608e1dc80dcb4088cebbbbe77d7e269ac13732c711a00/merged",
                "UpperDir": "/var/lib/docker/overlay2/6cbdbc6d1560ec1fe0b608e1dc80dcb4088cebbbbe77d7e269ac13732c711a00/diff",
                "WorkDir": "/var/lib/docker/overlay2/6cbdbc6d1560ec1fe0b608e1dc80dcb4088cebbbbe77d7e269ac13732c711a00/work"
            }
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:071d8bd765171080d01682844524be57ac9883e53079b6ac66707e192ea25956",
                "sha256:e0a311bc74f5b5421dc5c135921dece63824e1cce9e5f5717d07878315d3728a"
            ]
        }
    }
]


发布自己的镜像
[root@localhost ~]# docker commit -m "my centos" 4bf88ec1e25e wangcnc2005/centos
sha256:4a3a837b38d77a5024b22cf0265f69eef7a3b3ccb32c2f2c7ca3c5d52edb2320


[root@localhost ~]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: wangcnc2005
Password: 
Login Succeeded


[root@localhost ~]# docker push wangcnc2005/centos:latest
The push refers to a repository [docker.io/wangcnc2005/centos]
e0a311bc74f5: Pushed 
071d8bd76517: Pushed 
latest: digest: sha256:704978e57bd5486f145467a3ab314434bc02041a0f1aae137f43a5c81aea2506 size: 736

[root@localhost ~]# docker search wangcnc2005
INDEX       NAME                           DESCRIPTION   STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/wangcnc2005/centos   my centos     0           


容器的删除
[root@localhost ~]# docker commit -m="Hello Centos"  4bf88ec1e25e  hello_centos
sha256:3e99e17de7d4de201482f97635780ad7872cea5a8ce5a1a70312ce4cd330cf40
[root@localhost ~]# docker images|grep centos
hello_centos            latest              3e99e17de7d4        5 seconds ago       202 MB
hellocentos             latest              05c7c5c8c6f1        21 hours ago        202 MB
docker.io/centos        latest              1e1148e4cc2c        7 weeks ago         202 MB

[root@localhost ~]# docker rmi hello_centos
Untagged: hello_centos:latest
Deleted: sha256:3e99e17de7d4de201482f97635780ad7872cea5a8ce5a1a70312ce4cd330cf40

[root@localhost ~]# docker images|grep centos
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
hellocentos              latest              05c7c5c8c6f1        21 hours ago        202 MB
docker.io/centos         latest              1e1148e4cc2c        7 weeks ago         202 MB

标签: Docker

0

CentOS构建Docker

发布于:2019-1-25 10:08 作者:admin 浏览:2699 分类:系统架构
1.安装
[root@localhost test]# yum install docker

2.启动docker
[root@localhost test]# systemctl start docker

3.运行hello-world
[root@localhost test]# 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/


4.Docker 以 ubuntu15.10 镜像创建一个新容器,然后在容器里执行 bin/echo "Hello world",然后输出结果
[root@localhost test]#docker run ubuntu:15.10 /bin/echo "Hello world"
Hello world

5.通过docker的两个参数 -i -t,让docker运行的容器实现"对话"的能力
[root@localhost test]# docker run -i -t ubuntu:15.10 /bin/bash
root@8b6cdcd4f1bb:/# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var


6.后台模式运行命令
[root@localhost test]# docker run -d ubuntu:15.10 /bin/sh -c "while true; do echo hello world; sleep 1; done"
1472118a21aa6d4931b108f75f2d4b3fadefe6bd2e89317245f3a9b1f286930e
[root@localhost test]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
1472118a21aa        ubuntu:15.10        "/bin/sh -c 'while..."   2 minutes ago       Up 2 minutes                            loving_montalcini
[root@localhost test]# docker logs 1472118a21aa
hello world
hello world
hello world
hello world
[root@localhost test]# docker stop 1472118a21aa
1472118a21aa
[root@localhost test]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES



7.列出镜像列表
[root@localhost test]# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
docker.io/hello-world   latest              fce289e99eb9        3 weeks ago         1.84 kB
docker.io/ubuntu        15.10               9b9cb95443b5        2 years ago         137 MB

8.搜索镜像
[root@localhost test]# docker search lnmp
INDEX       NAME                                        DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/imagine10255/centos6-lnmp-php56   centos6-lnmp-php56                              50                   [OK]
docker.io   docker.io/twang2218/lnmp-nginx              这是 LNMP 示例中的 nginx 镜像                           16                   [OK]
docker.io   docker.io/winstonpro/lnmp                   based on ubuntu 14.04                           14                   
docker.io   docker.io/maxwhale/ubuntu14-lnmp1.2         Ubuntu14.04 lnmp1.2                             9                    [OK]
docker.io   docker.io/dzer/lnmp                         lnmp环境                                          8                    
docker.io   docker.io/domainer/centos-lnmp                                                              5                    [OK]
docker.io   docker.io/duckll/lnmp                       webservice                                      4                    [OK]
docker.io   docker.io/maxwhale/lnmp-docker              LNMP Docker                                     4                    [OK]
docker.io   docker.io/evagle/lnmp                       ubuntu14.04 + nginx + mysql + php + redis       3                    
docker.io   docker.io/idiswy/lnmp                       Ubuntu 16.04 + nginx 1.8.x + php7 + MySQL ...   3                    
docker.io   docker.io/c21xdx/lnmp13_cen6                php5.4                                          1                    [OK]
docker.io   docker.io/erguotou/docker-centos6-lnmp      lnmp environment in centos6                     1                    [OK]
docker.io   docker.io/fbraz3/lnmp                       An easy-to-use LNMP/LEMP image, with Ubunt...   1                    
docker.io   docker.io/gatherchou/docker-lnmp            docker-lnmp                                     1                    [OK]
docker.io   docker.io/inteye/lnmp                       LNMP1.2 (Linux, Nginx, Mysql, PHP). For de...   1                    
docker.io   docker.io/turtlell/lnmp                     first lnmp demo                                 1                    
docker.io   docker.io/twang2218/lnmp-php                这是 LNMP Docker 容器互联示例的 php 镜像                   1                    [OK]
docker.io   docker.io/zhaojianhui/lnmp                  LNMP环境                                          1                    
docker.io   docker.io/dahaitech/lnmp-douyou             douyou test lnmp                                0                    [OK]
docker.io   docker.io/huangguoji/lnmp                   lnmp.org的包                                      0                    
docker.io   docker.io/jamesatwork/docker-lnmpwp         A docker of LNMP & WordPress                    0                    [OK]
docker.io   docker.io/sixian67/lnmp                     this is my lnmp                                 0                    
docker.io   docker.io/thinksvip/lnmp                    LNMP docker production environment              0                    [OK]
docker.io   docker.io/twang2218/lnmp-mysql              This is the MySQL image of the LNMP docker...   0                    [OK]
docker.io   docker.io/zshtom/lnmp                       lnmp in centos 7                                0                    


9.下载镜像
[root@localhost test]# docker pull docker.io/idiswy/lnmp
Using default tag: latest
Trying to pull repository docker.io/idiswy/lnmp ... 
latest: Pulling from docker.io/idiswy/lnmp
f069f1d21059: Pull complete 
ecbeec5633cf: Pull complete 
ea6f18256d63: Pull complete 
54bde7b02897: Pull complete 
a3ed95caeb02: Pull complete 
ce9e695a6234: Pull complete 
346026b9659b: Pull complete 
929099c3258a: Pull complete 
064503d36445: Pull complete 
4c1032a6f902: Pull complete 
882f4453d31b: Pull complete 
Digest: sha256:ddb256e6834e5bd0dbaa0d9130ff94312ecdb1ae19669cc747e99620c4edd656
Status: Downloaded newer image for docker.io/idiswy/lnmp:latest

[root@localhost test]# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
docker.io/hello-world   latest              fce289e99eb9        3 weeks ago         1.84 kB
docker.io/idiswy/lnmp   latest              fbd7b7c5428e        2 years ago         335 MB
docker.io/ubuntu        15.10               9b9cb95443b5        2 years ago         137 MB

10.从已经创建的容器中更新镜像,并且提交这个镜像
[root@localhost test]# docker run -t -i fbd7b7c5428e /bin/bash
[root@e594c6c84c47:/sbin# apt-get update
Get:1 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB] 
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]                   
Get:3 http://archive.ubuntu.com/ubuntu xenial-security InRelease [109 kB]                  
Get:4 http://archive.ubuntu.com/ubuntu xenial/main Sources [1103 kB]                                                                                                                          
Get:5 http://archive.ubuntu.com/ubuntu xenial/restricted Sources [5179 B]                                                                                                                     
Get:6 http://archive.ubuntu.com/ubuntu xenial/universe Sources [9802 kB]                                                                                                                      
Get:7 http://nginx.org/packages/ubuntu xenial InRelease [4339 B]                                                                                                                              
Get:8 http://nginx.org/packages/ubuntu xenial/nginx Sources [14.1 kB]                                                                                                                         
Get:9 http://nginx.org/packages/ubuntu xenial/nginx amd64 Packages [20.1 kB]                                                                                                                  
Get:10 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB]                                                                                                                  
Get:11 http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [14.1 kB]                                                                                                            
Get:12 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [9827 kB]                                                                                                              
Get:13 http://archive.ubuntu.com/ubuntu xenial-updates/main Sources [415 kB]                                                                                                                  
Get:14 http://archive.ubuntu.com/ubuntu xenial-updates/restricted Sources [2684 B]                                                                                                            
Get:15 http://archive.ubuntu.com/ubuntu xenial-updates/universe Sources [303 kB]                                                                                                              
Get:16 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [1166 kB]                                                                                                          
Get:17 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [13.1 kB]                                                                                                    
Get:18 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [929 kB]                                                                                                       
Get:19 http://archive.ubuntu.com/ubuntu xenial-security/main Sources [175 kB]                                                                                                                 
Get:20 http://archive.ubuntu.com/ubuntu xenial-security/restricted Sources [2243 B]                                                                                                           
Get:21 http://archive.ubuntu.com/ubuntu xenial-security/universe Sources [116 kB]                                                                                                             
Get:22 http://archive.ubuntu.com/ubuntu xenial-security/multiverse Sources [3513 B]                                                                                                           
Get:23 http://archive.ubuntu.com/ubuntu xenial-security/main amd64 Packages [767 kB]                                                                                                          
Get:24 http://archive.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [12.7 kB]                                                                                                   
Get:25 http://archive.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [527 kB]                                                                                                      
Get:26 http://archive.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [6119 B]                                                                                                    
Fetched 27.3 MB in 4min 1s (113 kB/s)                                                                                                                                                         
Reading package lists... Done


11.通过命令 docker commit来提交容器副本,创建的目标镜像名
//-m:提交的描述信息,-a:指定镜像作者,d11aaceba824:容器ID,test/lnmp:v1 :指定要创建的目标镜像名
[root@localhost test]# docker commit -m="LNMP" -a="test" d11aaceba824 test/lnmp:v1
sha256:30a7c473b0ca8e02c1d1ac0ef3188e09d12649faf60cede37e2d7ccb877331e6

[root@localhost test]# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
test/lnmp               v1                  30a7c473b0ca        3 minutes ago       335 MB
docker.io/hello-world   latest              fce289e99eb9        3 weeks ago         1.84 kB
docker.io/idiswy/lnmp   latest              fbd7b7c5428e        2 years ago         335 MB
docker.io/ubuntu        15.10               9b9cb95443b5        2 years ago         137 MB


12.设置镜像标签
docker tag 镜像ID,这里是 860c279d2fec ,用户名称、镜像源名(repository name)和新的标签名(tag)。
使用 docker images 命令可以看到,ID为860c279d2fec的镜像多一个标签。

[root@localhost test]# docker tag 30a7c473b0ca test/lnmp:tagv1
[root@localhost test]# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
test/lnmp               tagv1               30a7c473b0ca        15 minutes ago      335 MB
test/lnmp               v1                  30a7c473b0ca        15 minutes ago      335 MB
docker.io/hello-world   latest              fce289e99eb9        3 weeks ago         1.84 kB
docker.io/idiswy/lnmp   latest              fbd7b7c5428e        2 years ago         335 MB
docker.io/ubuntu        15.10               9b9cb95443b5        2 years ago         137 MB


13:通过 Dockerfile 构建 hellodocker 
[root@localhost test]# cat Dockerfile
FROM centos
LABEL maintainer="Hello Docker"
RUN /bin/bash
CMD ["echo","Hello Docker"]

[root@localhost test]# docker build -t hellodocker .
Sending build context to Docker daemon 2.048 kB
Step 1/4 : FROM centos
Trying to pull repository docker.io/library/centos ... 
latest: Pulling from docker.io/library/centos
a02a4930cb5d: Pull complete 
Digest: sha256:184e5f35598e333bfa7de10d8fb1cebb5ee4df5bc0f970bf2b1e7c7345136426
Status: Downloaded newer image for docker.io/centos:latest
 ---> 1e1148e4cc2c
Step 2/4 : LABEL maintainer "Hello Docker"
 ---> Running in 20e2be20052b
 ---> f255f97c4984
Removing intermediate container 20e2be20052b
Step 3/4 : RUN /bin/bash
 ---> Running in a195ff956608

 ---> ec18faa97f10
Removing intermediate container a195ff956608
Step 4/4 : CMD echo Hello Docker
 ---> Running in fcd177b109d9
 ---> 075486018a06
Removing intermediate container fcd177b109d9
Successfully built 075486018a06

[root@localhost test]# docker images hellodocker
REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
hellodocker         latest              075486018a06        About a minute ago   202 MB

[root@localhost test]# docker run -i -t hellodocker
Hello Docker

标签: Docker

0

Failed to get D-Bus connection: Operation not permitted

发布于:2017-3-15 16:19 作者:admin 浏览:6610 分类:Linux

在Centos7的Docker里装好了httpd,运行报错:

systemctl start httpd.service  
Failed to get D-Bus connection: Operation not permitted

 

解决方案:

启动时设置参数  --privileged

使用该参数,container内的root拥有真正的root权限。
否则,container内的root只是外部的一个普通用户权限。

docker run --privileged centos /sbin/init

 

标签: Docker systemctl

0