centos7安裝docker及私人倉庫

來源:互聯網
上載者:User

centos7安裝docker及私人倉庫
1.初始化網路
安裝centos7後使用yum提示網域名稱無法解析.查看本網,ifconfig不可用,centos7中用ip命令代理了ifconfig.
ip addr, 顯示只有本地迴環地址。
cd /etc/sysconfig/network-scripts, 查看
網卡名對應的檔案
onboot為no
改為yes,重啟centos後,網路已聯通

2.uname -r檢查核心

3.yum update

4.添加yum源
sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

5.安裝
yum install docker-engine

6.開啟docker守護進程
$ sudo service docker start
查看
ps -ef | grep dockerd

7.檢查docker是否安裝成功
docker run hello-world
提示如下內容表示安裝成功
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c04b14da8d14: Pull complete
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
Status: Downloaded newer image for hello-world:latest

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.
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 Hub account:
https://hub.docker.com

For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

8.添加到開機啟動項
chkconfig docker on

9.建立docker私服
docker run -p 5000:5000 registry

測試:
下載鏡像
docker pull ubuntu:12.04

運行容器
docker run -i -t ubuntu:12.04 /bin/bash
修改檔案內容
root@ae00895eb68e:cd /home
echo "print 'test'" > t1.py
exit

提交到本地
docker commit -m "add t1.py" -a "lyc" ae00895eb68e ubuntu:12.04
將鏡像做tag
docker tag img_id 127.0.0.1:5000/ubuntu
提交到私人倉庫
docker push 127.0.0.1:5000/ubuntu
刪除本地鏡像
docker rmi --force img_id
從私人倉庫下載
docker pull 127.0.0.1:5000/ubuntu
運行容器
docker run -i -t 127.0.0.1:5000/ubuntu

查看檔案存在

匯出鏡像到檔案Dockersave -o [file_name] [img_id]|[repos_name]
匯入檔案到鏡像 docker load --input [img_file]

他們之間的關係如所示:

常用命令
運行容器 docker run -i -t ubuntu:12.04 /bin/bash
列出本地鏡像 docker images
顯示原生所有容器 docker ps -a
顯示正在啟動並執行容器 docker ps
搜尋鏡像 docker searchMySQL
刪除鏡像 docker rmi --force img_id
匯出鏡像到檔案 docker save -o [file_name] [img_id]|[repos_name]
匯入檔案到鏡像 docker load --input [img_file]
查看指定容器的日誌 docker logs [container_id] 或 docker logs -f [container_id]
停止容器 docker stop [container_id]
啟動一個停止的容器 docker start [container_id]
重啟容器 docker restart [container_id]
容器匯出 docker export [container_id] > ubuntu.tar.gz
刪除容器 docker rm -f [container_id]
匯入容器快照到鏡像 cat ubuntu.tar.gz | sudo docker import - [repos_name]
查看容器內的進程 docker top [container_id]
查看容器詳細資料 docker inspect [container_id]

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.