# How to expose a port on a live Docker container?

To expose a port on a live Docker container, you can use the `docker container port` command. Here are the steps:

1. To expose a port on a live Docker container, you need to first find the container ID or name. You can use the `docker container ls` command to list all running containers and find the ID or name of the container you want to expose the port on.
    
    ```bash
    docker container ls
    ```
    
2. Use the `docker container port` command to expose the port on the container. The syntax is as follows:
    
    ```bash
    docker container port <container> <port>
    ```
    

Where `<container>` is the container ID or name, and `<port>` is the port you want to expose. For example, to expose port 8080 on a container named `mycontainer`, you would run:

```bash
docker container port mycontainer 8080
```

This command will output the host IP address and port that maps to the container port you specified.

Note: Exposing a port on a live container does not automatically publish it to the host. To publish the port to the host, you need to stop and restart the container with the `-p` flag, specifying the host port and container port mappings. For example:

```bash
docker stop mycontainer
docker run -p 8080:8080 myimage
```

This will stop the container `mycontainer`, and start a new container based on `myimage` with the port mapping of `8080:8080`, exposing port 8080 to the host.