centos docker的搭建

学习目标:

docker学习一、


学习内容:

1、在centos上安装docker
2、docker的初步使用


1、在centos上安装docker

  • 使用国内 daocloud 一键安装命令:

curl -sSL https://get.daocloud.io/docker | sh

[root@1 ~]# curl -sSL https://get.daocloud.io/docker | sh
# Executing docker install script, commit: 26ff363bcf3b3f5a00498ac43694bf1c7d9ce16c
+ sh -c 'yum install -y -q yum-utils'
warning: /var/cache/dnf/BaseOS-929b586ef1f72f69/packages/libzstd-1.4.2-2.el8.x86_64.rpm: He
...
Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
         for more information.
[root@1 ~]# 
  • 待docker自动安装好之后,启动docker并检验docker是否安装好

sudo systemctl start docker :启动docker
sudo docker run hello-world hello-world : 映像来验证是否正确安装了 DockerEngine-Community

[root@1 ~]# sudo systemctl start docker
[root@1 ~]# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete 
Digest: sha256:8c5aeeb6a5f3ba4883347d3747a7249f491766ca1caa47e5da5dfcf6b9b717c0
Status: Downloaded newer image for hello-world:latest
...
For more examples and ideas, visit:
https://docs.docker.com/get-started/
[root@1 ~]# 

2、docker的初步使用

1、运行hello world

docker run ubuntu:15.10 /bin/echo “Hello world” :Docker 以 ubuntu15.10 镜像创建一个新容器,然后在容器里执行 bin/echo “Hello world”,然后输出结果

  • docker: Docker 的二进制执行文件
  • run: 与前面的 docker 组合来运行一个容器
  • ubuntu:15.10:指定要运行的镜像,Docker 首先从本地主机上查找镜像是否存在,如果不存在,Docker 就会从镜像仓库Docker Hub 下载公共镜像
  • /bin/echo “Hello world”: 在启动的容器里执行的命令
 [root@1 ~]# docker run ubuntu:15.10 /bin/echo "Hello world"
Unable to find image 'ubuntu:15.10' locally
15.10: Pulling from library/ubuntu
7dcf5a444392: Pull complete 
759aa75f3cee: Pull complete 
3fa871dc8a2b: Pull complete 
224c42ae46e7: Pull complete 
Digest: sha256:02521a2d079595241c6793b2044f02eecf294034f31d6e235ac4b2b54ffc41f3
Status: Downloaded newer image for ubuntu:15.10
Hello world
[root@1 ~]# docker run ubuntu:15.10 /bin/echo "Hello world"
Hello world

2、运行交互式的容器
进入Ubuntu:15.10这个系统容器

  • docker 的两个参数 -i -t,让 docker 运行的容器实现"对话"的能力:

-t: 在新容器内指定一个伪终端或终端。
-i: 允许你对容器内的标准输入 (STDIN) 进行交互。

[root@ecs-9da0 ~]# docker run -it ubuntu:15.10 /bin/bash
root@3de39315c277:/# cat /proc/version
Linux version 4.18.0-147.5.1.el8_1.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 8.3.1 20190507 (Red Hat 8.3.1-4) (GCC)) #1 SMP Wed Feb 5 02:00:39 UTC 2020
root@3de39315c277:/# 
root@3de39315c277:/# exit
exit
[root@ecs-9da0 ~]# 

3、启动容器到关闭容器

  • 创建一个以进程方式运行的容器:
[root@ecs-5ccd ~]# docker run -d ubuntu:15.10 /bin/sh -c "while true; do echo hello world; sleep 1; done"
2a0b740dc630d06b74b0caa8c17c98b4df18dc135316b4fb339c5c52aa5a233e
[root@ecs-5ccd ~]# 
[root@ecs-5ccd ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
2a0b740dc630        ubuntu:15.10        "/bin/sh -c 'while t…"   6 minutes ago       Up 6 minutes                            tender_robinson
  • COMMAND: 启动容器时运行的命令
  • STATUS: 容器状态

created(已创建)
restarting(重启中)
running 或 Up(运行中)
removing(迁移中)
paused(暂停)
exited(停止)
dead(死亡)

  • 使用 docker logs 命令,查看容器内的标准输出:
 [root@ecs-5ccd ~]# docker logs 2a0b740dc630
hello world
hello world
hello world
hello world
hello world
...

上面是以ID工作的,下面是以名字工作:

[root@ecs-5ccd ~]# docker logs tender_robinson
hello world
hello world
hello world

4、停止容器

[root@ecs-5ccd ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
2a0b740dc630        ubuntu:15.10        "/bin/sh -c 'while t…"   19 minutes ago      Up 19 minutes                           tender_robinson
[root@ecs-5ccd ~]# docker stop tender_robinson
tender_robinson
[root@ecs-5ccd ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@ecs-5ccd ~]# 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,你需要在 CentOS 上安装 Docker。可以参考 Docker 官方文档进行安装。 接着,你可以使用以下步骤在 Docker搭建 Bind9.16: 1. 创建一个目录,用于存储 Bind 配置文件和数据文件。 ``` mkdir bind cd bind ``` 2. 创建一个名为 `named.conf` 的 Bind 配置文件,并将其保存到 Bind 目录中。 ``` options { directory "/var/named"; recursion yes; allow-query { any; }; forwarders { 8.8.8.8; }; }; zone "." { type hint; file "named.ca"; }; zone "example.com" { type master; file "example.com.zone"; allow-update { none; }; }; ``` 3. 创建一个名为 `named.ca` 的文件,并将其保存到 Bind 目录中。可以从 Bind 官方网站上下载该文件。 ``` curl -o named.ca https://www.internic.net/domain/named.cache ``` 4. 创建一个名为 `example.com.zone` 的文件,并将其保存到 Bind 目录中。该文件包含了你想要管理的域名的 DNS 记录。 ``` $TTL 86400 @ IN SOA ns1.example.com. admin.example.com. ( 1 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 86400 ) ; Negative Cache TTL ; @ IN NS ns1.example.com. @ IN A 192.168.1.100 ns1 IN A 192.168.1.100 ``` 5. 运行以下命令启动一个 Bind 容器,并挂载 Bind 目录。 ``` docker run -d -p 53:53/udp --name bind \ -v /path/to/bind:/etc/bind \ -v /path/to/named:/var/named \ --restart always \ --hostname dns.example.com \ sameersbn/bind:9.16.1-20201219 ``` 其中,`/path/to/bind` 是你在第 1 步中创建的 Bind 目录的路径,`/path/to/named` 是一个空目录的路径,用于存储 Bind 数据文件。 6. 等待容器启动完成后,可以使用以下命令进入 Bind 容器。 ``` docker exec -it bind bash ``` 7. 在容器中,可以使用以下命令测试 Bind 是否正常工作。 ``` dig @127.0.0.1 example.com ``` 如果一切正常,你应该能够看到 `example.com` 的 DNS 记录。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值