Home >Operation and Maintenance >Docker >How docker sets port mapping for running containers

How docker sets port mapping for running containers

王林
王林Original
2020-03-24 11:28:144054browse

How docker sets port mapping for running containers

Method 1:

1. Obtain the container IP

Replace container_name with the container name in the actual environment

docker inspect `container_name` | grep IPAddress

2 , iptable forward port

Map the 8000 port of the container to the 8001 port of the docker host

iptables -t nat -A  DOCKER -p tcp --dport 8001 -j DNAT --to-destination 172.17.0.19:8000

Method 2:

1. Submit a running container as a mirror

docker commit containerid foo/live

2. Run the image and add the port

docker run -d -p 8000:80 foo/live /bin/bash

Recommended tutorial: docker tutorial

The above is the detailed content of How docker sets port mapping for running containers. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn