导航:首页 > 配服务器 > 如何配置docker服务器

如何配置docker服务器

发布时间:2022-04-26 06:43:12

❶ 如何在服务器上部署docker

Debian / Ubuntu

  1. sudo apt update

  2. sudo apt install docker.io

  3. sudo systemctl enable docker

  4. sudo systemctl start docker

RedHat / CentOS

  1. sudo yum update

  2. sudo yum install docker.io

  3. sudo systemctl enable docker

  4. sudo systemctl start docker

❷ 如何在linux服务器上安装Docker

安装一个docker,然后自己用命令行启动另外一个docker
下面是一个启动命令:
<pre t="code" l="bash">nohup docker daemon --selinux-enabled=false --log-driver=journald --storage-driver=overlay \
-H unix:///var/run/docker-bootstrap.sock -p /var/run/dockerbootstrap.pid \
--iptables=false --ip-masq=false --bridge=none --graph=/var/lib/dockerbootstrap \
2> /var/log/docker-bootstrap.log 1> /dev/null
注意几点:-H参数需要给出另外一个socket文件名-p给出另外一个pid文件名--graph 给出另外一个存放docker镜像容器的路径名称

❸ 如何部署 Docker Registry 服务 第2页

将创建一个 Container 来运行 Docker 的官方 Registry 镜像。你将推送(Push)一个镜像到这个 Registry 服务器,然后再从该 Registry 中拉取(Pull)同一个镜像。

这是个很好的练习,有助于理解客户端与本地 Registry 的基本交互。

1、安装 Docker。

2、从 Docker 公共 Registry 中运行 hello-world 镜像。

$ docker run hello-world
run 命令自动从 Docker 的官方镜像库中将 hello-world 镜像 pull 下来。

3、在 localhost 上启动 Registry 服务。

$ docker run -p 5000:5000 registry:2.0
这将在 DOCKER_HOST 上启动一个 Registry 服务,并在 5000 端口监听。
4、列出镜像。

$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2.0 bbf0b6ffe923 3 days ago 545.1 MB
golang 1.4 121a93c90463 5 days ago 514.9 MB
hello-world latest e45a5af57b00 3 months ago 910 B
这个列表应当包括一个由先前运行而得来的 hello-world 镜像。

5、为本地 repoistory 重新标记 hello-world 镜像。

$ docker tag hello-world:latest localhost:5000/hello-mine:latest
此命令使用
[REGISTRYHOST/]NAME[:TAG] 格式为 hello-world:latest 重新打标。REGISTRYHOST在此例中是
localhost。在 Mac OSX 环境中,得把 localhost 换成 $(boot2docker ip):5000。

6、列出新镜像。

$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2.0 bbf0b6ffe923 3 days ago 545.1 MB
golang 1.4 121a93c90463 5 days ago 514.9 MB
hello-world latest e45a5af57b00 3 months ago 910 B
localhost:5000/hello-mine latest ef5a5gf57b01 3 months ago 910 B
可以看到,新镜像已经出现在列表中。

7、推送新镜像到本地 Registry 中。

$ docker push localhost:5000/hello-mine:latest
The push refers to a repository [localhost:5000/hello-mine] (len: 1)
e45a5af57b00: Image already exists
31cbccb51277: Image successfully pushed
511136ea3c5a: Image already exists
Digest: sha256:
8、使用 curl 命令及 Docker Registry 服务 API v2 列出 Registry 中的镜像

❹ 不同操作系统Docker环境要求不同,如何快速部署

其实可以把问题报给客户,要求用户所有的电脑统一操作系统,然后再安装这个doctor,这样的环境就统一了,最好在安装之前把系统重做一次,用纯净的操作系统部署起来就更加快捷便利。

❺ 如何操作docker 容器的配置文件

步骤1:为我们的容器创建第一个镜像
# 以 centos 镜像作为基础镜像,我们启动自己的容器并在其中执行/bin/bash命令
# 注:-t -i 参数用于创建一个虚拟的命令行。
sudo docker run -t -i centos /bin/bash
现在我们已经成功的运行了自己的第一个容器,并且进入到容器的命令行界面中。在容器中,我们执行下面的命令:

yum -y update # 更新软件包
yum install which # 安装which命令
yum install git # 安装Git

安装完成后,按 Ctrl + d 来退出容器的命令行。
# 执行sudo docker ps -a,可以看到被我们终止的容器
CONTAINER ID IMAGE COMMAND CREATED……
da9031d3568f centos:6.4 /bin/bash 5 minutes ago…..
把我们所做的改变提交到一个新的容器:
# 这里我们创建一个自己的基础容器,容器中安装好了文章中所需的常用工具。读者的容器 id 可能与文章中的有所不同,以上一步 docker ps -a 的结果为准。
sudo docker commit da90 custom/base
容器成功提交后,执行 sudo docker images ,我们会看到刚才提交的容器(如下面的结果所示)。我们就以这个容器为基础容器,再来创建一个新的容器。
REPOSITORY TAG IMAGE ID CREATED
custom/base latest 05b6cecd370b 2 minutes ago
centos 6.4 539c0211cd76 10 months ago
centos latest 539c0211cd76 10 months ago…
步骤2:创建新的容器,并安装 apache
# 以 custom/base 容器为基础,运行一个新的容器。

sudo docker run -t -i custom/base /bin/bash

# 安装 httpd

yum install httpd

步骤3:再次提交新的容器
按 Ctrl + d 来退出容器的命令行,然后执行命令:
# 这个命令会把步骤2中我们安装 httpd 带来的改变提交到新的名为 custom/httpd 的容器镜像中。你的容器 id 可能会和文章中有所不同,以 sudo docker ps -a 命令的结果为准。

sudo docker commit aa6e2fc0b94c custom/httpd

你应该已经发现了,我们创建了一个带有 http 服务器并可以复用的容器镜像。你可以根据这种思想,为自己所需的每个组件都创建一个容器,然后把这些容器复用于开发环境或者生产环境。
步骤7:运行 http 服务器
# -v will Mount a volume from VM to the container which was also shared from host to Vagrant VM.
# -v 参数把主机共享给虚拟机的一个卷挂载到容器中
# -p forward VM port 80 to container port 80; VM port 80 is mapped to host port 8080 in Vagrantfile
# -p 参数把虚拟机的80端口映射到容器的80端口;虚拟机的80端口在 Vagrantfile 中被绑定到主机的8080端口,也就是:主机8080->虚拟机80->容器80
sudo docker run -t -i -p 80:80 -v /vagrant/htdocs:/var/www/html custom/httpd /bin/bash
# 启动 Apache
apachectl -k start

❻ 如何创建一个docker service 服务

1. 运行一个Docker实例
Docker首先会尝试从本地取得并运行所需的镜像,如果在本地主机上没有发现,它就会从Docker公共注册中心拉取。这里,我们将会拉取镜像并在 Docker 容器中创建一个Fedora实例,并连接到它的 tty 上的bash shell。
# docker run -i -t fedora bash

2.安装Apache网络服务器
现在,在我们的Fedora基本镜像实例准备好后,我们将会开始交互式地安装Apache网络服务器,而不是为它创建Dockerfile。为了做到这点,我们需要在终端或者shell运行以下命令。
# yum update

# yum install httpd

退出容器的 tty。
# exit

3.保存镜像
现在,我们要去保存在Fedora实例里做的修改。要做到这个,我们首先需要知道实例的容器ID。而为了得到ID,我们又需要运行以下命令(LCTT 译注:在容器外执行该命令)。
# docker ps -a

然后,我们会保存这些改变为一个新的镜像,请运行以下命令。
# docker commit c16378f943fe fedora-httpd

这里,修改已经通过使用容器ID保存起来了,镜像名字叫fedora-httpd。为了确认新的镜像是否在运行,我们将运行以下命令。
# docker images

4. 添加内容到新的镜像
我们自己新的Fedora Apache镜像正成功的运行,现在我们想添加一些我们网站的网页内容到Apache网络服务器,使得网站能够开箱即用。为做到这点,我们需要创建一个新的Dockerfile,它会处理从复制网页内容到启用80端口的所有操作。要达到这样的目的,我们需要使用我们最喜欢的文本编辑器创建Dockerfile文件,像下面演示的一样。
# nano Dockerfile
现在,我们需要添加以下的命令行到文件中。
FROM fedora-httpd
ADD mysite.tar /tmp/
RUN mv /tmp/mysite/* /var/www/html
EXPOSE 80
ENTRYPOINT [ "/usr/sbin/httpd" ]
CMD [ "-D", "FOREGROUND" ]

这里,上述的Dockerfile中,放在mysite.tar里的网页内容会自动解压到/tmp/文件夹里。然后,整个站点会被移动到Apache的网页根目录/var/www/html/,命令expose 80会打开80端口,这样网站就能正常访问了。其次,入口点放在了/usr/sbin/https里面,保证Apache服务器能够执行。

5. 构建并运行一个容器
现在,我们要用刚刚创建的Dockerfile创建我们的容器,以便将我们的网站添加到上面。为做到这,我们需要运行以下命令。
# docker build -rm -t mysite .

建立好我们的新容器后,我们需要要用下面的命令来运行容器。
# docker run -d -P mysite

❼ 如何部署 Docker Registry 服务

官方镜像下的简单示例

本节中,将创建一个 Container 来运行 Docker 的官方 Registry 镜像。你将推送(Push)一个镜像到这个 Registry 服务器,然后再从该 Registry 中拉取(Pull)同一个镜像。

这是个很好的练习,有助于理解客户端与本地 Registry 的基本交互。

1、安装 Docker。

2、从 Docker 公共 Registry 中运行 hello-world 镜像。

$ docker run hello-world
run 命令自动从 Docker 的官方镜像库中将 hello-world 镜像 pull 下来。

3、在 localhost 上启动 Registry 服务。

$ docker run -p 5000:5000 registry:2.0
这将在 DOCKER_HOST 上启动一个 Registry 服务,并在 5000 端口监听。
4、列出镜像。

$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2.0 bbf0b6ffe923 3 days ago 545.1 MB
golang 1.4 121a93c90463 5 days ago 514.9 MB
hello-world latest e45a5af57b00 3 months ago 910 B
这个列表应当包括一个由先前运行而得来的 hello-world 镜像。

5、为本地 repoistory 重新标记 hello-world 镜像。

$ docker tag hello-world:latest localhost:5000/hello-mine:latest
此命令使用 [REGISTRYHOST/]NAME[:TAG] 格式为 hello-world:latest 重新打标。REGISTRYHOST在此例中是 localhost。在 Mac OSX 环境中,得把 localhost 换成 $(boot2docker ip):5000。

6、列出新镜像。

$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2.0 bbf0b6ffe923 3 days ago 545.1 MB
golang 1.4 121a93c90463 5 days ago 514.9 MB
hello-world latest e45a5af57b00 3 months ago 910 B
localhost:5000/hello-mine latest ef5a5gf57b01 3 months ago 910 B
可以看到,新镜像已经出现在列表中。

7、推送新镜像到本地 Registry 中。

$ docker push localhost:5000/hello-mine:latest
The push refers to a repository [localhost:5000/hello-mine] (len: 1)
e45a5af57b00: Image already exists
31cbccb51277: Image successfully pushed
511136ea3c5a: Image already exists
Digest: sha256:
8、使用 curl 命令及 Docker Registry 服务 API v2 列出 Registry 中的镜像:

$ curl -v -X GET http://localhost:5000/v2/hello-mine/tags/list* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...* Connected to localhost (127.0.0.1) port 5000 (#0)> GET /v2/hello-mine/tags/list HTTP/1.1> User-Agent: curl/7.35.0> Host: localhost:5000> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< Docker-Distribution-Api-Version: registry/2.0
< Date: Sun, 12 Apr 2015 01:29:47 GMT
< Content-Length: 40
<
{"name":"hello-mine","tags":["latest"]}
* Connection #0 to host localhost left intact
也可以通过在浏览器中访问以下地址来获取这些信息:http://localhost:5000/v2/hello-mine/tags/list

9、从你的本地环境中移除所有未使用的镜像:

$ docker rmi -f $(docker images -q -a )
此命令仅用于说明目的;移除镜像强制 run 从 Registry 而不是从本地缓存拉取。如果在这之后运行docker images,在你的镜像列表中,应该看不到任何 hello-world 或 hello-mine 的实例。

$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2.0 bbf0b6ffe923 3 days ago 545.1 MB
golang 1.4 121a93c90463 5 days ago 514.9 MB
10、试运行 hello-mine。

$ docker run hello-mine
Unable to find image 'hello-mine:latest' locally
Pulling repository hello-mine
FATA[0001] Error: image library/hello-mine:latest not found
命令 run 运行失败,因为你的新镜像在 Docker 公共 Registry 中是不存在的。
11、现在,尝试指定镜像的 Registry 来运行镜像:

$ docker run localhost:5000/hello-mine
如果你在这之后运行 docker images, 你会发现里面多了一个 hello-mine 的实例。

使 Docker 官方 Registry 镜像做好生产环境准备

Docker 的官方镜像只为简单的测试或除错准备。其配置对多数生产环境来讲都不适用。例如,任何能访问服务器 IP 的客户端,都能推送及拉取镜像。参看下一节,获取使该镜像做好生产环境准备的信息。

理解生产环境的部署

当部署一个用于生产环境发布的 Registry 时,须考虑如下因素:

BACKEND STORAGE 应在何处存储镜像?
ACCESS AND/OR AUTHENTICATION 用户是否应拥有全部或受控的访问权限?这取决于你为公众提供镜像服务,还是只为公司内部提供。
DEBUGGING 当问题或状况发生时,是否有解决这些它们的方法。日志由于可以看到问题动向,这使其很有用。
CACHING 快速提取镜像可能至关重要,如果依赖镜像进行测试、构建,或有其他自动化系统的话。
我们可以配置 Registry 功能特性,用以调整适配这些因素。可以在命令行里指定选项来干这个,或者更通常地,用一个 Registry 配置文件来完成此事。配置文件是 YAML 格式的。

Docker 的官方 Repository 镜像用以下配置文件做了预置:

version: 0.1
log:
level: debug
fields:
service: registry
environment: development
storage:
cache:
layerinfo: inmemory
filesystem:
rootdirectory: /tmp/registry-dev
http:
addr: :5000
secret: asecretforlocaldevelopment
debug:
addr: localhost:5001
redis:
addr: localhost:6379
pool:
maxidle: 16
maxactive: 64
idletimeout: 300s
dialtimeout: 10ms
readtimeout: 10ms
writetimeout: 10ms
notifications:
endpoints:
- name: local-8082
url: http://localhost:5003/callback
headers:
Authorization: [Bearer <an example token>]
timeout: 1s
threshold: 10
backoff: 1s
disabled: true
- name: local-8083
url: http://localhost:8083/callback
timeout: 1s
threshold: 10
backoff: 1s
disabled: true
这个配置非常基本,可以看到这在生产环境下会有一些问题。例如,http 区块详述了运行 Registry 的主机的 HTTP 服务器配置,但服务器没有使用甚至是最低要求的传输层安全性(TLS)配置。接下来我们将配置这些东西。

❽ 如何搭建及使用docker registry

registry是什么?
registry是Docker的镜像存储服务,docker hub上的registry镜像见Registry官方镜像,更多详细信息请参见源码
搭建registry
在服务器上执行如下命令安装docker,这里选择腾讯云(Ubuntu Server 14.04.1 LTS 64位)镜像来创建服务器
curl -fsSL https://get.docker.com/ | sh

安装docker-compose Docker Compose是一个定义及运行多个Docker容器的工具。使用Docker Compose只需要在一个配置文件中定义多个Docker容器,然后使用一条命令将多个容器启动,Docker Compose会通过解析容器间的依赖关系,按先后顺序启动所定义的容器。详见Docker Compose
curl -L https://github.com/docker/compose/releases/download/1.8.0/docker-compose-$(uname -s)-$(uname -m) > /usr/local/bin/docker-compose
chmod a+x /usr/local/bin/docker-compose

启动registry服务,此例中包含nginx和registry两个容器,涉及的包及配置文件请参见附件,解压后,直接执行如下命令即可创建服务。
docker-compose up -d

停止服务
docker-compose stop

重启服务
docker-compose restart

下线服务
docker-compose down

上传镜像
因为上面搭建的registry服务是http的,所以docker启动参数需要配置--insecure-registry localhost选项,修改/etc/default/docker文件
DOCKER_OPTS="--insecure-registry localhost"

重启docker
service docker restart

拉取上传镜像 docker pull;docker tag;docker push(tag默认为latest)
docker pull hello-world
docker tag hello-world localhost/library/hello-world
docker push localhost/library/hello-world

下载镜像
docker pull localhost/library/hello-world

删除镜像
docker rmi localhost/library/hello-world

获取镜像仓库列表
# curl http://localhost/v2/_catalog
{"repositories":["library/hello-world"]}

未上传镜像前的输出如下:
# curl http://localhost/v2/_catalog
{"repositories":[]}

获取镜像tag列表
# curl -X GET http://localhost/v2/library/hello-world/tags/list
{"name":"library/hello-world","tags":["latest"]}

获取镜像manifests信息
# curl -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -X GET http://localhost/v2/library/hello-world/manifests/latest
{
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"config": {
"mediaType": "application/vnd.docker.container.image.v1+json",
"size": 1473,
"digest": "sha256:"
},
"layers": [
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 974,
"digest": "sha256:"
}
]
}

其中即为执行docker images时看到的IMAGE ID。 layers表示了镜像的层次关系,可以通过layers中的digest来拉取blob,见下面获取镜像blob
获取镜像blob
在上面获取hello-world:latest镜像的manifests信息中可以看到其只有一个layer,以此为例来看如何获取镜像blob。从拉取的结果可以看到获取的blob与文件sha256是一致的。执行docker pull实际上就是首先获取到镜像的manifests信息后,再拉取blob的。
# curl -s -X GET http://localhost/v2/library/hello-world/blobs/sha256: -o hello-world.blob
# ls -l hello-world.blob
-rw-r--r-- 1 root root 974 Nov 23 09:56 hello-world.blob
# sha256sum hello-world.blob
hello-world.blob

##删除镜像(soft delete)
首先通过curl -i 参数获取到镜像的Docker-Content-Digest,registry 2.3及以后的版本必须在header中指定Accept: application/vnd.docker.distribution.manifest.v2+json,否则默认返回的是schema1的digest,其与schema2的digest不同,使用不指定上述头信息返回的digest删除时会返回404。
# curl -i -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -X GET http://localhost/v2/library/hello-world/manifests/latest

HTTP/1.1 200 OK
Server: nginx/1.11.5
Date: Wed, 23 Nov 2016 02:17:51 GMT
Content-Type: application/vnd.docker.distribution.manifest.v2+json
Content-Length: 524
Connection: keep-alive
Docker-Content-Digest: sha256:
Docker-Distribution-Api-Version: registry/2.0
Etag: "sha256:"

{
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"config": {
"mediaType": "application/vnd.docker.container.image.v1+json",
"size": 1473,
"digest": "sha256:"
},
"layers": [
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 974,
"digest": "sha256:"
}
]
}

根据上一步返回的Docker-Content-Digest删除,返回202表示删除成功
# curl -k -v -s -X DELETE http://localhost/v2/library/hello-world/manifests/sha256:

* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 80 (#0)
> DELETE /v2/library/hello-world/manifests/sha256: HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost
> Accept: */*
>
< **HTTP/1.1 202 Accepted**
* Server nginx/1.11.5 is not blacklisted
< Server: nginx/1.11.5
< Date: Wed, 23 Nov 2016 02:29:59 GMT
< Content-Type: text/plain; charset=utf-8
< Content-Length: 0
< Connection: keep-alive
< Docker-Distribution-Api-Version: registry/2.0
<
* Connection #0 to host localhost left intact

确认结果
# curl -X GET http://localhost/v2/library/hello-world/tags/list
{"name":"library/hello-world","tags":null}

删除镜像(hard delete)
在上一步中,只是删除了镜像的manifests信息,解引用的blob还在占用磁盘空间,执行如下命令可以查看可以删除的blob
docker exec -it myregistry_registry_1 /bin/registry garbage-collect --dry-run /etc/registry/config.yml

要删除blob,释放磁盘空间,需要执行下面的命令。需要特别注意的是在执行下面的命令时registry必须是只读模式(只读模式可在registry配置文件中设置),否则可能会导致数据不一致。
docker exec -it myregistry_registry_1 /bin/registry garbage-collect /etc/registry/

阅读全文

与如何配置docker服务器相关的资料

热点内容
java线程内存溢出 浏览:185
cad显示顺序的命令 浏览:189
飞度pdf 浏览:177
聚尚美app在哪里 浏览:988
退出全局命令 浏览:648
node命令退出 浏览:817
我的世界怎么做有工会的服务器 浏览:384
程序员达到 浏览:81
万维网如何查看远程服务器账号 浏览:60
怎么报程序员培训班 浏览:959
怎么帮男朋友解压缓解焦虑 浏览:568
java程序员用什么浏览器 浏览:786
禅诗pdf 浏览:629
cprimer英文pdf 浏览:241
两位数乘以两位数的减编算法 浏览:461
选了程序员有错吗 浏览:490
起点app怎么加密 浏览:104
安卓如何设计界面 浏览:878
工商银行app如何查询历史账单 浏览:45
火鸟门户源码版多少钱 浏览:277