DEV Community

Shahriyar Al Mustakim Mitul
Shahriyar Al Mustakim Mitul

Posted on

Docker series (Part 3): Running 3 different containers with 3 different images in Docker

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
Here we have told the environment variable to set a root password
Let's check it

docker container logs db
Enter fullscreen mode Exit fullscreen mode

db is the name we gave to this container
Now, you can see the ROOT_PASSWORD
Image description
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
setting the name of the container as webserver and port to 8080:80
NOw, let's write

docker ps
Enter fullscreen mode Exit fullscreen mode

to see the running containers. ( an old command)

Image description

2nd one done!

Let's create the 3rd one

This time we will create a container using nginx image

WImage description
We have set the container name to proxy and also port to 80:80
Let's see the total list

Image description

It is better to run

docker container ls
Enter fullscreen mode Exit fullscreen mode

Now, lets see the localhost

curl localhost
Enter fullscreen mode Exit fullscreen mode

Image description
Image description

for 80:80 port which means nginx container. Now, check the localhost for httpd container which had port 8080 with it.

curl localhost:8080
Enter fullscreen mode Exit fullscreen mode

Image description
Image description

you can see that, they are working.

Now, lets stop them and then remove them

Image description
WE just used few letters of the container ID while stopping them.
Now, lets check if they exist or not

Image description
SO, now we will remove them using their container id's again

Image description
So, done!!!

Image description

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.

Top comments (0)