Let's type this in our terminal to run a nginx web server
sudo docker container run --publish 80:80 nginx
go to your browser and type "localhost". You can see a page of nginx.
This is what basically happened
Stop the container using Ctrl+C
Now, it is not active any more.
Let's create another one and this time , we will run it in the back ground.
sudo docker container run --publish 80:80 --detach nginx
This detach command actually runs it in the background and after we run it, we get a container ID
again, you can go to your browser and type "localhost" and see the nginx server.
now go to the terminal and type
sudo docker container ls
This shows which container is running.
Let's stop it
sudo docker container stop <1st few digits of the container id>
Now, let's see how many containers we actually created because we stopped them but not deleted them ever.
sudo docker container ls -a
You can also go to your VS Code studio and install "Docker" from extensions . This will also track how many containers etc are there
also, you can see some unique name here like "elastic_saha"", "elastic_newton". This was randomly provided as you did not provide them.
Let's provide them a name and create another container .
sudo docker container run --publish 80:80 --detach --name mitul_shahriyar nginx
Your VS code will look like this
You can go to your browser & type for "localhost" to see a nginx server.
let's see all the container list again
sudo docker container ls -a
let's see some logs of this container which we gave the name "mitul_shahriyar"
Also , you may know commands to run docker or play with
Now, lets remove them
sudo docker container rm <1st few digits of container id>
We have 1 container running which we will forcefully remove
Top comments (1)
I imagine the only commands that need
sudo
are those where you're binding to a port below 1024. All the other ones should be run as a regular user.