This Blog is to share our knowledge and expertise on Linux System Administration and VMware Administration

Friday, January 19, 2018

Working with Docker Container - Exposing a port while starting a container

Exposing a port while starting a container

There are a number of ways by which ports on the container can be exposed. One of them is through the run command, which we will cover in this chapter. The other ways are through the Docker file and the --link command.

Syntax:  docker run --expose=PORT [ OPTIONS ]  IMAGE[:TAG]  [COMMAND]  [ARG...]

to expose port 22 while starting a container, run the following command:

root@Docker:~# docker run --expose=22 -i -t centos /bin/bash
[root@88a0e1ab48df /]#
root@Docker:~# docker ps
CONTAINER ID  IMAGE   COMMAND  CREATED          STATUS            PORTS       NAMES
88a0e1ab48df    centos     "/bin/bash"   27 seconds ago  Up 26 seconds   22/tcp  amazing_bohr

For help with the docker run use --help

No comments:

Post a Comment