# 使用docker swarm啟動Web服務

Docker Swarm Cluster現在已啟動並正在運行，是時候在Docker Swarm模式下啟動Web服務了。在管理器節點上，運行以下命令以部署Web服務器服務：`docker service create --name webserver -p 8880:80 httpd`

```
docker service create --name webserver -p 8880:80 httpd
```

docker service ls您應該看到以下輸出：

```
sudo docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
dk7qnjx65dnx        webserver           replicated          1/1                 httpd:latest        *:8880->80/tcp

```

接下來，使用以下命令在兩個容器之間擴展Web服務器服務： `docker service scale webserver=2`

```
ebserver scaled to 2
overall progress: 1 out of 2 tasks 
1/2: preparing 
2/2: running

overall progress: 2 out of 2 tasks 
1/2: running   
2/2: running   
verify: Service converged 
```

然後，使用以下命令檢查Web服務器服務的狀態：`docker service ps webserver`您應該看到以下輸出：

```
sudo docker service ps webserver
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
wdpxz2bh9vu7        webserver.1         httpd:latest        pi-GB-BSi5A-6200    Running             Running 3 minutes ago                        
olv9p594q03w        webserver.2         httpd:latest        ubuntu-mate         Running             Running 58 seconds ago  
```

![](/files/-M2HXeWk5NYYDkeMGPpb)

使用overlay網路

![](/files/-M2H_kPKug4hhKBlqO7f)

![](/files/-M2HsSKlEuIYtoGV78O_)

啟動樹梅派 http 服務

![](/files/-M2Hw5TzDuUTNOuCmLzw)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kawsing.gitbook.io/opensystem/docker-swarm/shi-yong-docker-swarm-qi-dong-web-fu-wu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
