Run Docker Container

run hello-world
  1. Since the hello-world image wasn’t already present on your disk, Docker downloaded it from a default registry, the Docker Hub.
  2. Docker created a container based on the hello-world image.
  3. After that it put some text on console so we get that container is running.
  4. And last, The container stopped.

Container Management Commands

  • docker ps: lists the containers that are still running. Add the -a switch in order to see containers that have stopped. it give container id with details.


Server Container

Till now, We just saw how to run short-lived containers. They usually do some processing and display some output. However, there’s a very common use for long-lived containers: server containers. Whether you want to host a web application, an API, or a database, you want a container that listens for incoming network connections and is potentially long-lived. let see for Long-lived container now

Listening for Incoming Network Connections

let’s use NGINX web server. If I simply run the server, my machine does not route incoming requests to it unless I use the -p switch on the docker run command.


When a container writes files, it writes them inside of the container. Which means that when the container dies (the host machine restarts, the container is moved from one node to another in a cluster, it simply fails, etc.) all of that data is lost. It also means that if you run the same container several times in a load-balancing scenario, each container will have its own data, which may result in inconsistent user experience.


Did you notice above i write mysql:5.7 not only mysql. so here 5.7 is tag for mysql Image. Tag is use for versioning.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store