Now, if we want to verify that the USER environment variable created inside the container or not, we can connect to the container using the ‘exec’ command with ‘-i’ and ‘-t’ options together as shown below: –Įxplanation: In the above snapshot, we have connected to the container with its name, however, we can use container ID as well and the container must be in running state in order to connect to it. Now, set environment variables using the ‘-e’ option as below:ĭocker run -d -e "USER=test1" -name nginx-con nginxĮxplanation: In the above example, we have used the ‘-e’ option to set an environment variable USER to test1. Let’s run the container in detached mode to overcome the above issue using the ‘-d’ option as shown below:Įxplanation: In the above example, we only got the container ID because the container is now running in the background and also this time daemon did not pull the image because nginx image is already available locally. We use ‘ctrl+c’ to exit the container, however, it stops the container as well. Also, we can see that the cursor is stuck and we did not get the terminal because the container is running in the foreground. If we don’t use the ‘–name’ option then the daemon randomly picks any name and assigned to the container. Let’s give a name to the container using the ‘–name’ option as below:Įxplanation: In the above example, created an nginx container named ‘nginx-con’. Let’s run our first container ‘hello world without specifying any options as shown below:Įxplanation: In the above snapshot, we can see that the ‘hello-world’ image was not available locally so daemon first pulled that image locally and ran the container and the ‘hello-world’ container has shown some data on STDOUT and exited. Here are the following examples mention below Example #1 When we run the ‘docker run’ command on the terminal, Docker daemon searches for the mentioned Docker image locally and if it finds the image locally then it creates a writeable layer over the specified Docker image and starts the container using specified command and if it does not find the image locally then it firsts pull that image from the registry and by default, it goes to ‘’ if there is no local registry mentioned in the daemon.json file. We can use the ‘–help’ option to list all available options of this command as below: – The above options are the most common that we frequently use while working with the ‘docker run’ command. w, –workdir: It allows to set the working directory of the container v, –volume: It is used to bind volume to the container for persistent storage t, –tty: It allocates terminal and mostly used with the ‘-i’ option. –rm: It removes the container as soon as container exit or stop running –restart: It allows us to specify restart policy for the container p, –publish: It is used to publish container’s ports to host –network: It is used to connect the container to a different network than the default –name: It is used to specify the name of the container –mount: It is used to mount filesystem to the container
![docker run image in terminal docker run image in terminal](https://www.middlewareinventory.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-05-at-4.34.59-PM.png)
m, –memory: It is used to set memory limit in bytes –log-opts: It is used to specify options to log-driver.
#Docker run image in terminal driver#
–log-driver: It is used to specify the logging driver for the container, it overrides the default log-driver –link: It adds a link to another container