About Me

My photo
I am MCSE in Data Management and Analytics with specialization in MS SQL Server and MCP in Azure. I have over 13+ years of experience in IT industry with expertise in data management, Azure Cloud, Data-Canter Migration, Infrastructure Architecture planning and Virtualization and automation. Contact me if you are looking for any sort of guidance in getting your Infrastructure provisioning automated through Terraform. I sometime write for a place to store my own experiences for future search and read by own blog but can hopefully help others along the way. Thanks.

Docker Port Mapping: Avoiding Conflicts When Running Multiple Containers

Question:-

Would the following two commands create a port conflict error with each other?

       docker container run -p 80:80 -d nginx

        docker container run -p 8080:80 -d nginx

Ans:-

No, the two commands will not create a port conflict error. Docker maps the container's ports to the host's ports, and allows multiple containers to map the same host port to different container ports.

In this example, the first command maps the container's port 80 to the host's port 80, and the second command maps the container's port 80 to the host's port 8080. These mappings are different, so they will not cause a conflict.

You can run multiple containers that map the same container port to different host ports, and they will not interfere with each other. This allows you to run multiple instances of the same service on different host ports, which can be useful for testing, development, and other purposes.


Question:-

I ran 'docker container run -p 80:80 nginx' and my command line is gone and everything looks frozen. Why?

Ans:-

It's likely that the container is running in the foreground and has taken over the terminal, preventing you from entering new commands. By default, Docker runs containers in the foreground and attaches to the terminal, which can cause the terminal to appear "frozen" if the container is running an interactive process.

To regain control of the terminal, you can use the Ctrl + C key combination to stop the container. If the container is still running in the background, you can use the docker container stop command to stop it, followed by the container ID or name.

--->    docker container stop <container_id_or_name>

If you want to run the container in the background, you can use the -d or --detach option when starting the container. This will run the container in the background and return control of the terminal to you.

  ---> docker container run -d -p 80:80 nginx


No comments: