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:
Post a Comment