设为首页 收藏本站
查看: 514|回复: 0

[经验分享] CentOS7安装Docker与使用

[复制链接]

尚未签到

发表于 2018-4-22 09:49:45 | 显示全部楼层 |阅读模式
1.安装docker
yum install docker -y[root@i-8ew12yu3 jenkins]# docker version
Client:
Version:         1.12.6
API version:     1.24
Package version: docker-1.12.6-28.git1398f24.el7.centos.x86_64
Go version:      go1.7.4
Git commit:      1398f24/1.12.6
Built:           Fri May 26 17:28:18 2017
OS/Arch:         linux/amd64
Cannot connect to the Docker daemon. Is the docker daemon running on this host?[root@i-8ew12yu3 jenkins]# service docker start
Redirecting to /bin/systemctl start  docker.service2.使用docker使用命令行的工具来检索名字为“tutorial”的镜像
[root@i-8ew12yu3 jenkins]# docker search tutorial
INDEX       NAME                                                 DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/georgeyord/reactjs-tutorial                This is the backend of the React comment b...   4                    [OK]
docker.io   docker.io/egamas/docker-tutorial                     Funny manpages                                  2                    [OK]
docker.io   docker.io/mhausenblas/kairosdb-tutorial              GitHub fetcher for KairosDB tutorial            1                    [OK]
docker.io   docker.io/mjansche/tts-tutorial                      Software for a Text-to-Speech tutorial          1                    [OK]
docker.io   docker.io/odk211/spree-tutorial                                                                      1                    [OK]
docker.io   docker.io/trausch/tutorial-delly                     Cancer Genomics Tutorial of Delly               1                    [OK]
docker.io   docker.io/activeeon/par-connector-tutorial           Do the par-connector tutorial with R. The ...   0                    [OK]
docker.io   docker.io/ajyounge/muelu-tutorial                    Modified muelu tutorial                         0                    [OK]
docker.io   docker.io/algas/wercker-tutorial                     wercker tutorial                                0                    [OK]
docker.io   docker.io/biopython/biopython-tutorial               Biopython with Tutorial running on top of ...   0                    [OK]
docker.io   docker.io/camphor/python-tutorial                    camphor-/python-tutorial                        0                    [OK]
docker.io   docker.io/chris24walsh/flask-aws-tutorial            Runs a simple flask webapp demo, with the ...   0                    [OK]
docker.io   docker.io/delta2323/jnns2015-tutorial                                                                0                    [OK]
docker.io   docker.io/filipe/react-tutorial                      React comment box example, React tutorial:...   0                    [OK]
docker.io   docker.io/guillon/qemu-tutorial                      Image for QEMU tutorial based on qemu-plugins   0                    [OK]
docker.io   docker.io/kobe25/docker-tutorial                     Docker Tutorial                                 0                    [OK]
docker.io   docker.io/locksmithdon/ssb-tutorial                  The image used in a Secure Scuttlebutt tut...   0                    [OK]
docker.io   docker.io/michelesr/docker-tutorial                  Docker Tutorial                                 0                    [OK]
docker.io   docker.io/onekit/rest-tutorial                       REST API server-side tutorial. How to do i...   0                    [OK]
docker.io   docker.io/paulcos11/docker-tutorial                  docker tutorial                                 0                    [OK]
docker.io   docker.io/rinnocente/gromed-ts-tutorial-2017         GRO[macs] + [plu]MED for the Trieste tutor...   0                    [OK]
docker.io   docker.io/rubygem/hydra-tutorial                     Auto-Generated Image for Ruby Gem hydra-tu...   0                    [OK]
docker.io   docker.io/sampige/koha-tutorial                      Koha Tutorial for Schools                       0                    [OK]
docker.io   docker.io/tiagofilipe12/bionode-watermill-tutorial   This is a docker image for running bionode...   0                    [OK]
docker.io   docker.io/zinuzoid/docker-swarm-tutorial-worker      https://github.com/zinuzoid/docker-swarm-t...   0                    [OK]使用docker命令来下载镜像
[root@i-8ew12yu3 jenkins]# docker pull learn/tutorial
Using default tag: latest
Trying to pull repository docker.io/learn/tutorial ...
latest: Pulling from docker.io/learn/tutorial
271134aeb542: Downloading [================>                                  ] 23.25 MB/71.04 MB
271134aeb542: Downloading [================>                                  ] 23.79 MB/71.04 MB
271134aeb542: Pull complete
Digest: sha256:2933b82e7c2a72ad8ea89d58af5d1472e35dacd5b7233577483f58ff8f9338bd查看已下载的镜像
[root@i-8ew12yu3 jenkins]# docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
docker.io/learn/tutorial   latest              a7876479f1aa        4 years ago         128 MB在docker容器中运行hello world!
docker run命令有两个参数,一个是镜像名,一个是要在镜像中运行的命令。
[root@i-8ew12yu3 jenkins]# docker run learn/tutorial  echo “hello word”
“hello word”在容器中安装新的程序(wget命令)
[root@i-8ew12yu3 jenkins]# docker run learn/tutorial apt-get install -y wget
Reading package lists...
Building dependency tree...
The following extra packages will be installed:
  libidn11
The following NEW packages will be installed:
  libidn11 wget
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 389 kB of archives.
After this operation, 970 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ precise/main libidn11 amd64 1.23-2 [112 kB]
Get:2 http://archive.ubuntu.com/ubuntu/ precise/main wget amd64 1.13.4-2ubuntu1 [277 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 389 kB in 25s (15.5 kB/s)
Selecting previously unselected package libidn11.
(Reading database ... 7545 files and directories currently installed.)
Unpacking libidn11 (from .../libidn11_1.23-2_amd64.deb) ...
Selecting previously unselected package wget.
Unpacking wget (from .../wget_1.13.4-2ubuntu1_amd64.deb) ...
Setting up libidn11 (1.23-2) ...
Setting up wget (1.13.4-2ubuntu1) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place使用docker ps -l命令获得安装完wget命令之后容器的id。然后把这个镜像保存为learn/wget。
[root@i-8ew12yu3 jenkins]# docker ps -l
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
ea5537bf71f7        learn/tutorial      "apt-get install -y w"   54 seconds ago      Exited (0) 27 seconds ago                       kickass_aryabhata保存对容器的修改
[root@i-8ew12yu3 jenkins]# docker commit ea5537bf71f7 learn/wget
sha256:7c5939899fb36a9aed6b7dc9e12edd3704cef1ae5a3e9ae52ea714082e79e972
执行完docker commit命令之后,返回新版本镜像的id号运行新的镜像
到现在为止,我们已经建立了一个完整的、自成体系的docker环境,并且安装了wget命令在里面。它可以在任何支持docker环境的系统中运行
在新的镜像中运行wget “http://blog.csdn.net/yown” 命令。
[root@i-8ew12yu3 jenkins]# docker run learn/wget wget “http://blog.csdn.net/yown”
“http://blog.csdn.net/yown”: Scheme missing.[root@i-8ew12yu3 jenkins]# docker ps -l
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                     PORTS               NAMES
2e16a889dfa1        learn/wget          "wget “http://blog."   5 minutes ago       Exited (1) 5 minutes ago                       focused_dubinsky检查运行中的镜像
[root@i-8ew12yu3 jenkins]# docker inspect ea5537bf71f7
[
    {
        "Id": "ea5537bf71f7263ceaf58d0246fc9705dce97cc4e57dab08eebd280a469bbc03",
        "Created": "2017-07-03T07:45:17.356235721Z",
        "Path": "apt-get",
        "Args": [
            "install",
            "-y",
            "wget"
        ],
        "State": {
            "Status": "exited",
            "Running": false,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 0,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2017-07-03T07:45:17.800829779Z",
            "FinishedAt": "2017-07-03T07:45:44.067117909Z"
        },
        "Image": "sha256:a7876479f1aae32c0716d7a85b5151af26f533fe48efa086010105cba02f5163",
        "ResolvConfPath": "/var/lib/docker/containers/ea5537bf71f7263ceaf58d0246fc9705dce97cc4e57dab08eebd280a469bbc03/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/ea5537bf71f7263ceaf58d0246fc9705dce97cc4e57dab08eebd280a469bbc03/hostname",
        "HostsPath": "/var/lib/docker/containers/ea5537bf71f7263ceaf58d0246fc9705dce97cc4e57dab08eebd280a469bbc03/hosts",
        "LogPath": "",
        "Name": "/kickass_aryabhata",
        "RestartCount": 0,
        "Driver": "devicemapper",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "journald",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "docker-runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Name": "devicemapper",
            "Data": {
                "DeviceId": "6",
                "DeviceName": "docker-253:1-528373-12c0f46fc46238bab100eec9a829f441b40439a9da2c6c097dbbe08d0528ad06",
                "DeviceSize": "10737418240"
            }
        },
        "Mounts": [],
        "Config": {
            "Hostname": "ea5537bf71f7",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": true,
            "AttachStderr": true,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [],
            "Cmd": [
                "apt-get",
                "install",
                "-y",
                "wget"
            ],
            "Image": "learn/tutorial",
            "Volumes": {},
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "19d48e001859f8e25085fd4b13db7f925529541c3bef199514d6aaaf03ec621d",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": null,
            "SandboxKey": "/var/run/docker/netns/19d48e001859",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "c178ae9004cdca9f3438687ccf856df3caf694a418864c722c7721f430c38eb2",
                    "EndpointID": "",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": ""
                }
            }
        }
    }
]  如果发布自己的镜像 :
  a. 首先在www.docker.com注册账户,登录并在https://cloud.docker.com/repository/list 页面创建自己的库
  b. 将刚才我们做的镜像起个新的名字:
$docker tag learn/wget:latest yown/learn:latest

  c. 在命令行登录:
$docker login

d. 上传
$docker push yown/learn:latest

Do you really want to push to public registry? [y/n]: y
The push refers to a repository [docker.io/yown/learn] (len: 1)
ad2245a8acd8: Pushing [=========================> ] 6.482 MB/12.48 MB

  


  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-450296-1-1.html 上篇帖子: centos 7 lamp环境 下篇帖子: centos 释放缓存
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表