How do I assign a port mapping to an existing Docker container?

0 votes

I'm creating a new container from an image. Is there a way to assign a port mapping to an existing Docker container?

Can anyone help me with this?

Thanks

Sep 18, 2018 in DevOps & Agile by shubham
• 6,890 points
292 views

1 answer to this question.

0 votes

Below are some steps which you can follow:

First, stop the running container

docker stop container_id

Commit the container

docker commit container_id container_id2 

Container_id2 is a new image which is made from container_id2 container.

Try to re-run from the commited image

docker run -p 8080:8080 -td container_id2

I hope it will resolve your query.

answered Sep 18, 2018 by Damon Salvatore
• 5,510 points

Related Questions In DevOps & Agile

+1 vote
2 answers

How do I run Apache server from Docker without mapping to a location?

If you're seeing a 500 error, that's ...READ MORE

answered Oct 18, 2018 in DevOps & Agile by lina
• 8,160 points
87 views
+14 votes
5 answers

How do I run a cron job inside a docker container

If you can SSH into your server ...READ MORE

answered Jul 27, 2018 in DevOps & Agile by Kalgi
• 46,110 points
3,512 views
0 votes
1 answer
0 votes
1 answer

How do I restart a single container with docker-compose?

Actually it's not that difficult. Here is ...READ MORE

answered Nov 8, 2018 in DevOps & Agile by Damon Salvatore
• 5,510 points
1,193 views
0 votes
1 answer
0 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 57,300 points
270 views
0 votes
1 answer
0 votes
1 answer

How to edit file after I shell to a docker container?

Since docker images are trimmed to bare minimum ...READ MORE

answered Sep 11, 2018 in DevOps & Agile by Damon Salvatore
• 5,510 points
106 views