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

How docker sets port mapping for running containers

王林
Release: 2020-03-24 11:28:14
Original
4050 people have browsed it

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
Copy after login

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
Copy after login

Method 2:

1. Submit a running container as a mirror

docker commit containerid foo/live
Copy after login

2. Run the image and add the port

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template