docker:containers:run_a_docker_container
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
docker:containers:run_a_docker_container [2020/11/11 11:50] – 192.168.1.1 | docker:containers:run_a_docker_container [2020/11/11 12:12] (current) – 192.168.1.1 | ||
---|---|---|---|
Line 70: | Line 70: | ||
---- | ---- | ||
- | ===== Example | + | ===== Run a Container and Publish Container Ports ===== |
+ | <code bash> | ||
+ | docker container run --name docker-nginx -d -p 8080:80 nginx | ||
+ | </ | ||
- | Launching a container is simple as **docker run** + the image name you would like to run + the command to run within the container. | + | where: |
- | If the image doesn' | + | * **8080** is the port of the Docker host. |
+ | * **80** is the port of the container where the application is running. | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | An optional host-ip can also be set: | ||
+ | |||
+ | <code bash> | ||
+ | docker container run -p [host-ip]: | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Remove the Container After Exit ===== | ||
+ | |||
+ | <code bash> | ||
+ | docker container run --rm mongo | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Run a Container and Mount Host Volumes ===== | ||
+ | |||
+ | By default, Docker | ||
+ | |||
+ | 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 | ||
+ | |||
+ | <code bash> | ||
+ | docker container run --name docker-nginx -d -p 8080:80 -v / | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | This option is useful for anyone running a database or application that requires persistence within Docker. | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Example ===== | ||
For example, if you ran **/bin/echo hello world** as your command, the container will start, print hello world and then stop: | For example, if you ran **/bin/echo hello world** as your command, the container will start, print hello world and then stop: |
docker/containers/run_a_docker_container.1605095400.txt.gz · Last modified: 2020/11/11 11:50 by 192.168.1.1