1.安装dokcer
[root@node01 ~]# dnf -y install docker docker-compose
[openeuler@localhost testhx]$ su root
密码:
su: 拒绝权限
sudo dnf -y install docker docker-compose

2.将用户加入 docker 用户组(永久解决)
# 1. 创建docker用户组(如果不存在)
sudo groupadd docker
# 2. 将当前用户加入docker组
sudo usermod -aG docker $USER
# 3. 更新组权限(需要重新登录或执行以下命令)
newgrp docker
# 4. 验证
docker version

3.修改 /etc/docker/daemon.json

华为云SWR基础功能免费,适合个人和小规模使用;企业级应用或高频使用时需按量付费。
添加私有仓库,则 /etc/docker/daemon.json

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": [
    "https://docker.mirrors.ustc.edu.cn",
    "https://hub-mirror.c.163.com"
  ]
}
EOF
sudo systemctl restart docker

cat /etc/docker/daemon.json
方案2
sudo tee /etc/docker/daemon.json <<-'EOF'
{
    "registry-mirrors": [
        "https://docker-0.unsee.tech",
        "https://docker-cf.registry.cyou",
        "https://docker.1panel.live"
    ]
}
EOF


# 1. 官方hello-world镜像(仅几KB)
sudo docker pull hello-world
# 3. BusyBox镜像(约1MB)
sudo docker pull busybox
docker images  # 查看已下载镜像


编辑/etc/sysconfig/docker配置文件 
openEuler 22.03中,系统重启后会丢失自定义的容器网络,导致容器无法重新启动。可通过配置/etc/sysconfig/docker文件,在其中加入内容:DISABLE_CRASH_FILES_DELETE=true
[root@host1 ~]# vim /etc/sysconfig/docker 
sudo vim /etc/sysconfig/docker
……此处省略文件原有内容……
DISABLE_CRASH_FILES_DELETE=true

4、运行相关的案例

4.1拉取

[openeuler@localhost docker]$ sudo docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
e6590344b1a5: Already exists
Digest: sha256:ec153840d1e635ac434fab5e377081f17e0e15afab27beb3f726c3265039cfff
Status: Downloaded newer image for hello-world:latest
[openeuler@localhost docker]$

4.2运行demo

[openeuler@localhost docker]$ echo $USER
openeuler
[openeuler@localhost docker]$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              74cc54e27dc4        6 months ago        10.1kB
[openeuler@localhost docker]$
[openeuler@localhost docker]$
[openeuler@localhost docker]$
[openeuler@localhost docker]$ docker run hello-world

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

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

[openeuler@localhost docker]$

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐