Docker run command creates a container from an image and runs it.
docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
Here we run the nginx Docker image.
docker run -d -p 80:80 --name webserver nginx
-d = detach after starting the 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

Leave a Reply