# Docker Run

As seen below while we run

docker run redis. It pulls out the latest version of redis. But what if we want some older versions.

![](/files/-MER2i5gkigVWP4jYAZR)

We need to specify version with our image. This is called a TAG. But if we didn't define any TAG Docker will consider TAG as latest as shown above. (latest version of the software)

\>>>As a user how do we find information about these versions & to see what is latest.Go to DockerHUB & see the associated versions.

![](/files/-MER3UoEvlK3zhtKeSuh)

**RUN - STDIN :**

By default the Docker container doesn't listen to a standrad input thats why once we run the docker image it directly print out the result without asking any input from user.

Currently its running in a non-interactive mode.

-it >>interactive terminal.

**RUN - PORT Mapping : Now how user access the application , Application running on port 5000.**

I could access my application by using port 5000. But what IP i have to use to access it from Web browser. There are 2 options available for this.

a) One is to use the IP of the Docker containeer. Every Docker container gets an IP assigned by default . In this case it is 172.17.0.2 . Remember this is an internal IP & its only accessible within the Docker HOST. Now if we open browser within the Docker HOST then open application using <http://172.17.0.2:5000> **. But since this is the Internal IP user outside the Docker HOST cannot access it using this IP.**

**b) To access it outside we colud use the IP of the Docker HOST which is 192.168.1.5 but for that to work we must have mapped the port inside the Docker container to a free port on the Docker HOST. For example : If i want user to access my application  thorught port 80 on my Docker HOST , I could map port 80 of localhost to port 5000 on the Docker container using the -p paramter in the run command shown below :**

**Now all traffic on port 80 on my Docker HOST will get routed to port 5000 inside the Docker container.**

\>>We can multiple instances of our application & mapped them to different ports on the Docker HOST or run instances of diffrent applications on diffrent ports.

> We cannot map to same port on Docker HOST more then once

![](/files/-MER7iw6oqqazhpz2AL4)

RUN - Volume Mapping :

Now to see how data is persisted in a Docker container :

\>>The Docker Conatiner has its own isolated File System & any changes to any files happen within the conatiner .

\>>Let assume we are storing our data in MySQL container & anyhow we have to move or remove our container , then the all data that resides in database blown away.

\>>If we would like to persist data , then we have to map a directory outisde the Docker container on Docker HOST to a directory inside the container.

\>>This way when the Docker container runs it will implicitely mount the external directory to a folder inside the Docker container. In this way all our data will now be stored in the external volume . Now even if we delete container the data still safe.

![](/files/-MER9nbRfVjyWBehxOEA)

**Inspect Container : If we would like to see specific details about a container :**

![](/files/-MERA_7DI3XD32_sRC3o)

**Finally how do we see the logs of a container ran in the background :**

![](/files/-MERAmHC2K8T9uTzIa_A)

{% embed url="<https://github.com/kodekloudhub/webapp-color/blob/master/Dockerfile>" %}

[**https://github.com/kodekloudhub/webapp-color**](https://github.com/kodekloudhub/webapp-color)

![](/files/-MERBIBakWbmAcznoAxF)

Checkout the code from above & run the application .&#x20;

set environment varaibles using export APP\_COLOR=blue

Find out the internal IP of the container using docker inspect command.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://architectures.gitbook.io/project/docker/docker-run.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
