Sunday 19 May 2019

Docker : Mapping port of host system to port of container application


In my previous post, I explained how to run the wildfly application in a docker container on some random port chosen by docker. There is another way also, using -p, you can specify the host port and corresponding mapping port in docker container.

Stop or delete any wildfly container that is deployed previously.

To delete the container, execute below command
docker container rm -f {containerId/containerName}

To stop the container, execute below command.
docker container stop {containerId/containerName}

$docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                     NAMES
8ff3181fef3e        jboss/wildfly       "/opt/jboss/wildfly/…"   12 hours ago        Up 12 hours         0.0.0.0:32768->8080/tcp   naughty_poitras
$
$docker container rm -f 8ff3181fef3e
8ff3181fef3e
$
$docker container ls -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Map host port 1234 to container port 8080
Execute below command.

docker run -d -p1234:8080 jboss/wildfly

$docker run -d -p1234:8080 jboss/wildfly
27221a96591e7e69d8a70fce3dcda3ab10edf8a01b4e1bd133dc73772b98c6fc
$
$docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
27221a96591e        jboss/wildfly       "/opt/jboss/wildfly/…"   5 seconds ago       Up 5 seconds        0.0.0.0:1234->8080/tcp   unruffled_pasteur


Open the url 'http://localhost:1234/' in browser, you can see wildfly welcome screen.



Previous                                                 Next                                                 Home

No comments:

Post a Comment