docker容器怎么开端口

2023-04-11 04:31:00 docker 容器 开端
Docker containers can be used to open ports in several ways. The most common way is to use the -p option when starting a container. This will map a port on the host machine to a port inside the container. For example, the following command will start a container and map port 8080 on the host machine to port 80 inside the container: docker run -p 8080:80 my-container Another way to open a port is to use the --publish option when starting a container. This has the same effect as the -p option. Another way to open a port is to use the EXPOSE command in the Dockerfile. This will cause Docker to expose the specified port when the container is started. For example, the following Dockerfile will expose port 8080: FROM my-image EXPOSE 8080 Once the container is started, you can use the docker port command to see which ports are exposed: docker port my-container This will show you the mapping of ports between the host machine and the container.

相关文章