LoginSignup
2
1

More than 5 years have passed since last update.

dockerで連番のportをforwardする

Posted at

docker runのmanに以下のように書いてあります。

  -p, --publish=[]
      Publish a container's port, or 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.  (e.g., docker run -p 1234-1236:1222-1224 --name
   thisWorks -t busybox but not docker run -p 1230-1236:1230-1240 --name RangeContainerPortsBiggerThanRangeHostPorts -t busybox) With ip: docker run -p
   127.0.0.1:$HOSTPORT:$CONTAINERPORT --name CONTAINER -t someimage Use docker port to see the actual mapping: docker port CONTAINER $CONTAINERPORT

なので、-p 1234-1236:1222-1224という形式で指定ができるようですね。

$ docker run -itd --name renban -p 1234-1236:1222-1224/udp ubuntu
bdee0c27e5c6ead4ff5c1bdd615e02111d27a0ec41d4d70905dc60a662aa45f9
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                                                                    NAMES
bdee0c27e5c6        ubuntu              "/bin/bash"         4 seconds ago       Up 1 second         0.0.0.0:1234->1222/udp, 0.0.0.0:1235->1223/udp, 0.0.0.0:1236->1224/udp   renban

設定できました。
終わり。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1