CentOS7安装Docker与使用

1.安装docker 
yum install docker -y
[[email protected] 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?
[[email protected] jenkins]# service docker start 
Redirecting to /bin/systemctl start  docker.service
2.使用docker
使用命令行的工具来检索名字为“tutorial”的镜像 
[[email protected] 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命令来下载镜像 
[[email protected] 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
查看已下载的镜像 
[[email protected] 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命令有两个参数,一个是镜像名,一个是要在镜像中运行的命令。 
[[email protected] jenkins]# docker run learn/tutorial  echo “hello word”
“hello word”
在容器中安装新的程序(wget命令) 
[[email protected] 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。 
[[email protected] 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
保存对容器的修改 
[[email protected] jenkins]# docker commit ea5537bf71f7 learn/wget 
sha256:7c5939899fb36a9aed6b7dc9e12edd3704cef1ae5a3e9ae52ea714082e79e972
执行完docker commit命令之后,返回新版本镜像的id号
运行新的镜像 
到现在为止,我们已经建立了一个完整的、自成体系的docker环境,并且安装了wget命令在里面。它可以在任何支持docker环境的系统中运行
在新的镜像中运行wget “http://blog.csdn.net/yown” 命令。 
[[email protected] jenkins]# docker run learn/wget wget “http://blog.csdn.net/yown”
“http://blog.csdn.net/yown”: Scheme missing.
[[email protected] 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
检查运行中的镜像 
[[email protected] 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

时间: 2024-10-01 18:45:14

CentOS7安装Docker与使用的相关文章

Centos7安装Docker CE

原文:Centos7安装Docker CE 每次安装Docker都要去找文档,或者每次安装的都不一样,还是要好好管理自己的这些东西,下次用的时候可以省很多的时间 Docker的早期版本称为docker或docker-engine:现在的Docker CE软件包称为docker-ce ; 环境 Centos7 安装脚本 #!/bin/bash #filename: install_docker.sh #Version: v1.0.0 #Author: LiLe #Date: 20190306 #C

centos7安装docker并配置php运行环境

原文:centos7安装docker并配置php运行环境 一.安装docker 首先我们先来了解一下什么是docker. docker是一个虚拟化的技术,基于 Linux 内核,是将进程进行封装隔离,由于隔离的进程独立于宿主机和其它的隔离的进程,因此也可以称为容器.很多人把docker理解为虚拟机,其实不是的,因为它不需要进行硬件虚拟以及运行完整操作系统等额外开销的,docker的出现也是为了解决在各种复杂的环境下不需要做任何的修改还可以保证程序正常稳定的运行,也就是环境一致性的问题,当然还有k

centos7 安装docker

最小化安装linux 关闭selinux编辑 /etc/selinux/config设定 SELINUX=disabled 重新启动 shutdown -r now 获取ip动态地址#dhclient 更新yum#yum -y update 安装ifconfig但是ifconfig在centos7上默认不在安装了,ifconfig属于net-tools包,而且vmtools必须要使用ifconfig这个命令,所以必须安装net-tools包,#yum -y install net-tools即可

centos7安装docker

1.查看linux发行版,内核 [[email protected]~]# cat /etc/redhat-release #查看版本号 CentOS Linux release 7.1.1503 (Core) [[email protected] ~]# uname -r #查看Linux内核 c3.10.0-229.el7.x86_64 2.替换阿里云yum源 1 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.

Centos7安装docker应用容器引擎

Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源. Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化. 容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app),更重要的是容器性能开销极低. Docker的应用场景 Web 应用的自动化打包和发布. 自动化测试和持续集成.发布. 在服务型环境中部署和调整数据库或其他的后台应用. 从头编译或者扩

Docker系列之CentOS7安装Docker(一)

0.前言 整体架构目录:ASP.NET Core分布式项目实战-目录 一.瞎扯淡(只讲有用的) 感兴趣的同学可以上网搜索一下docker具体的介绍.我这边主要介绍偏实战的内容,不喜勿喷,有问题也请指出. 官方给出的介绍:docker就是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任务流行的linux机器上,实现虚拟化. 我想说的是docker 就是 一个车的发动机引擎,引擎来提供动力,提供车上各个依赖引擎的组件使之运行,那么这里的组件就是容器.讲的

CentOs6和Centos7安装docker

Centos6安装的时候是按照网上的步骤, yum install -y epel-release yum install -y docker -io service docker start 失败了,说是未被识别的服务,接下来 yum remove docker yum remove docker-io vi  /etc/yum.repos.d/docker.repo 放入下面的内容 [dockerrepo] name=Docker Repository baseurl=https://yum

centos7安装docker并设置开机启动

版本要求:查看内核版本,需大于3.10 [[email protected] ~]# uname -r 3.10.0-327.10.1.el7.x86_64 更新内核:如果是生产机器务必慎重更新内核,避免出现不必要的问题. sudo yum update 安装docker [[email protected] ~]# curl -sSL https://get.docker.com/ | sh + sh -c 'sleep 3; yum -y -q install docker-engine'

Centos7 安装docker ce

一. 安装docker 1.升级rpm包 yum -y update 2. 通过命令设置Docker CE 资源库: yum install -y yum-utils yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo 3.生成缓存 sudo yum makecache fast 4.查看可下载版本 yum list docker-ce --showduplicates | s