Docker series (Part 3): Running 3 different containers with 3 different images in Docker
Tags: docker
Published: 2022-06-06 11:10:41

Let's run a container of mysql image which has been detached and also has a name db and a variable set to it 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dhar6alk5hbc3t5xqemi.png)
Here we have told the environment variable to set a root password
Let's check it  

```
docker container logs db
```
db is the name we gave to this container
Now, you can see the ROOT_PASSWORD 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zp2tv5cecbap5ad8aznk.png)
You may ask what is this root password? Then check the first image again to find the environment variable. We asked it to create a root password for us using value yes to permit it.

1 done!
Let's create another container using image httpd

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m96ord2wu8thtfz3zuhg.png)
setting the name of the container as webserver and port to  8080:80
NOw, let's write 

```
docker ps
```
to see the running containers. ( an old command)

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

2nd one done!

Let's create the 3rd one

This time we will create a container using nginx image

 W![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j5ok1af2ge23npnhzlqs.png)
We have set the container name to proxy and also port to 80:80
Let's see the total list

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

It is better to run 

```
docker container ls
```
  
 Now, lets see the localhost

```
curl localhost
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0o6ifvujen4spltyhb4j.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9kfmz4wrxtx8lk9nekkt.png)
 
 
for 80:80 port which means nginx container. Now, check the localhost for httpd container which had port 8080 with it.

```
curl localhost:8080
```
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w9pksthdvvmlo4iliqrc.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cyn6m8yy26671zr06tw3.png)
 
 you can see that, they are working.

Now, lets stop them and then remove them

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tcfdadg8n4qwzq25jw2r.png)
WE just used few letters of the container ID while stopping them.
Now, lets check if they exist or not

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0pnrjo2f26b9u1x828nj.png)
SO, now we will remove them using their container id's again

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

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

<img src="https://c.tenor.com/Tvd3VKwtse0AAAAC/cat-cute.gif">

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

Answer: You didn't specify the -d flag to detach it in the background, and there aren't any logs coming across the screen because you haven't connected to the published port yet, so Nginx has nothing to log about.