Docker Run

Docker run command create container from IMAGE and run it.

docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]

Here we run nginx docker image.

docker run -d -p 80:80 --name  webserver nginx

-d = detach after starting container.

-p 80:80 = port 80 on host machine is mapped to port 80 inside container.

Now you will be able to access Nginx server by visiting IP of host machine.

To stop running container, run

root@ok-vm:~# docker stop webserver
webserver
root@ok-vm:~# 

To start

docker start webserver

Docker Volumes

Docker volume can be specified with -v, it allow you to share a folder in host machine with docker container.

docker run -d -p 80:80 -v /var/www/html:/usr/share/nginx/html --name  webserver nginx

Here folder /var/www/html on host machine will be mounted as /usr/share/nginx/html in the container. This allows you to make the data persistent.

See Docker

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *