[Docker] How to expose ports on live containers

[Docker] How to expose ports on live containers

Goal

  • To add port exposure on running container


Intro

  • I intalled MariaDB container and it was running
  • However, it was not bound on host


Practice

1. Check bining ports

# docker port [CONTAINER_NAME] [PORT_NUMBER]

screenshot001


2. Create new container from running container

2.1. Stop running container

# docker stop  [CONTAINER_NAME]

screenshot002


2.2. Create container from running container

# docker commit [RUNNING_CONTAINER_NAME] [NEW_CONTAINER_NAME]

screenshot003


2.3. Remove original container and create container which is applied exposure port again

# docker rm [RUNNING_CONTAINER_NAME]

# docker run -p {HOST_IP}:{[HOST_PORT]}:[CONTAINER_PORT] [OPTIONS] [CONTAINER_NAME] [CREATED_CONTAINER_NAME]

-p, –publish : Publish a container’s port(s) to the host

::[CONTAINER_PORT] : HOST_RANDOM_PORT <-> CONTAINER_PORT

screenshot004


3. Check port binding

3.1. Check exposure port

# docker ps

screenshot005


3.2. Connection test by Telnet

$ telnet [HOST_IP] [PORT]

screenshot006



References

댓글남기기

-->