CentOS构建Docker2
admin 发布于:2019-1-30 9:03 分类:系统架构 有 2184 人浏览,获得评论 0 条 标签: Docker
查看版本 [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