1. 程式人生 > >Docker學習與實踐(一)

Docker學習與實踐(一)

docker

一、docker的安裝

1.依賴包安裝

yum install -y yum-utils device-mapper-persistent-data lvm2

2.添加yum源

yum-config-manager --add-repo https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
yum-config-manager --enable docker-ce-edge
#配置為安裝最新版Docker CE

3.安裝docker

yum install docker-ce

*官方為了簡化安裝流程提供了便捷的安裝腳本

curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh --mirror Aliyun

4.啟動docker

systemctl enable docker
systemctl start docker

5.建立docker用戶和組
6.測試docker是否安裝完成

[docker@dockertest ~]$ docker run hello-world
Unable to find image ‘hello-world:latest‘ locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete 
Digest: sha256:083de497cff944f969d8499ab94f07134c50bcf5e6b9559b27182d3fa80ce3f7
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.
    (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://cloud.docker.com/

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

7.配置鏡像加速器並重啟服務

cat /etc/docker/daemon.json 
{
"registry-mirrors": [
"https://registry.docker-cn.com"
 ]
}
systemctl daemon-reload
sudo systemctl restart docker

#學習文檔地址:https://github.com/yeasy/docker_practice/blob/master/SUMMARY.md

Docker學習與實踐(一)