Docker series (Part 2): Starting an nginx Web server on Ubuntu
Tags: nginx, docker
Published: 2022-05-30 06:44:19

Let's type this in our terminal to run a nginx web server

```
sudo docker container run --publish 80:80 nginx
```


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c5bfr5xo9xq83lbjb69l.png)

go to your browser and type "localhost". You can see a page of nginx.
 
This is what basically happened

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mnkgu9oh0a34ft03qfs3.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cwj1fze1oh4by53zuin9.png)

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
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pvkw20idlyznxdk6nyo8.png)
This shows which container is running.

Let's stop it

```
sudo docker container stop <1st few digits of the container id>
```


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ckqd38nemqeop9y3j7tu.png)
So, it has been stopped. 

Now, let's see how many containers we actually created because we stopped them but not deleted them ever.

```
sudo docker container ls -a
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dayysbjcn6nle90u0nlh.png)
You can also go to your VS Code studio and install "Docker" from extensions . This will also track how many containers etc are there

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/559bscac8jabxd1nhetv.png)

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
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/panunare3uverupd4jem.png)
Your VS code will look like this

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/smvojjbg8dmva59vtxm4.png)

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
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9cxzpz2u5a3h5l1kgbq9.png)
let's see some logs of this container which we gave the name "mitul_shahriyar"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2rikiod1clq8tu2mmadh.png)

Also , you may know commands to run docker or play with
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yj76k12kt0pjfay43dd6.png)

Now, lets remove them

```
sudo docker container rm <1st few digits of container id>
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gq2wr8ouc50arq5lhe2p.png)


 We have 1 container running which we will forcefully remove

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i503l7rlyh39g4i6m9dt.png)