User Tools

Site Tools


docker:containers:run_a_docker_container

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
docker:containers:run_a_docker_container [2020/11/11 11:51] 192.168.1.1docker:containers:run_a_docker_container [2020/11/11 12:12] (current) 192.168.1.1
Line 67: Line 67:
 docker container run --name docker-nginx -it nginx /bin/bash docker container run --name docker-nginx -it nginx /bin/bash
 </code> </code>
 +
 +----
 +
 +===== Run a Container and Publish Container Ports =====
 +
 +<code bash>
 +docker container run --name docker-nginx -d -p 8080:80 nginx
 +</code>
 +
 +where:
 +
 +  * **8080** is the port of the Docker host.
 +  * **80** is the port of the container where the application is running.
 +
 +<WRAP info>
 +**NOTE:**  You can verify the port 8080 using the URL http://docker-host-ip:8080 in your web browser.
 +
 +An optional host-ip can also be set:
 +
 +<code bash>
 +docker container run -p [host-ip]:[host-port]:[container-port]
 +</code>
 +
 +</WRAP>
 +
 +
 +----
 +
 +===== Remove the Container After Exit =====
 +
 +<code bash>
 +docker container run --rm mongo
 +</code>
 +
 +----
 +
 +===== Run a Container and Mount Host Volumes =====
 +
 +By default, Docker containers do not save the data. When a container is stopped and the process is completed, all data generated by the container is removed.
 +
 +Sometimes you may need to run a container that requires persistent storage. In that case, you can use Docker volume to make the data persist and also share it across the multiple containers.
 +
 +<code bash>
 +docker container run --name docker-nginx -d -p 8080:80 -v /mnt:/var/www nginx
 +</code>
 +
 +<WRAP info>
 +**NOTE:**  Any data written to **/var/www** within the container is actually accessing **/mnt** on the host.
 +
 +This option is useful for anyone running a database or application that requires persistence within Docker.
 +
 +</WRAP>
 +
  
 ---- ----
docker/containers/run_a_docker_container.1605095466.txt.gz · Last modified: 2020/11/11 11:51 by 192.168.1.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki