zno2

http server , docker hub

https://hub.docker.com/_/httpd/

1.Create a Dockerfile in your project

FROM httpd:2.4
COPY ./public-html/ /usr/local/apache2/htdocs/

2. 在同级目录创建文件夹 public-html 

3. 将你想要访问的文件添加到 public-html 中

4. 创建镜像

docker build -t my-apache2 .

注:创建名为my-apache2 的镜像 , Dockerfile 位置在当前目录

5. 运行

docker run -dit -p 9090:80 --name my-running-app my-apache2

注:

--expose=[]

Expose a port or a range of ports inside the container.
These are additional to those exposed by the `EXPOSE` instruction

-P Publish all exposed ports to the host interfaces
-p=[]

Publish a container᾿s port or a range of ports to the host
format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort
Both hostPort and containerPort can be specified as a
range of ports. When specifying ranges for both, the
number of container ports in the range must match the
number of host ports in the range, for example:
-p 1234-1236:1234-1236/tcp

When specifying a range for hostPort only, the
containerPort must not be a range. In this case the
container port is published somewhere within the
specified hostPort range. (e.g., `-p 1234-1236:1234/tcp`)

(use 'docker port' to see the actual mapping)

--link="" Add link to another container (<name or id>:alias or <name or id>)

即: 访问主机的9090 端口时,映射到 80 端口(这个端口是容器 expose 的端口)

 

注:--name 是指定容器的名称

docker ps --format "table{{.ID}}\t{{.Names}}" -f name=my
CONTAINER ID        NAMES
65ca46ea5596        my-running-app

 

posted on 2023-06-06 13:11  zno2  阅读(11)  评论(0编辑  收藏  举报

导航