dockerrunredis//Runacontainerfromanimagewiththelatestversiondockerrunredis:4.0//Addatagtorunaspecificversiondockerrun-it-dubuntubashroot@dc43c98b31c9:/#//-dmeanswillrunindetachmodeandletthecontainerruninthebackground//theoppositeofdetachisdockerattach ${containerName}//-itforinteractivity (prompt andwaitingforSTDIN)//Andhashvaluethatisgeneratedrandomlybydockertoidentifywhich//containersiswhich.dockerps//Toseeallthecontainersthatarecurrentlyrunninginbackgrounddockersps-a//Tocheckallrunningandexitedcontainersdockerexec-it ${containerId or names} bash//Toruntherunningcontainerinthebackground.dockerstop ${containerId or names}//Tostopcontainerrunninginthebackgrounddockerrm ${containerId or names} //Todeleteexitedcontainerdockerimages//Tolistofavailableimagesdockerrmi ${image name} //Toremoveimages.Mustensurealldependenciesareremovedfirstdockerpull ${image name} //Willonlypulltheimageandnotrunthecontainerdockerinspect ${container name or container id}//Givemoredetailonspecificcontainerinjsonformat//CanbeusedalsotoinspectEnvVariableusedtorunthecontainerdockerlogs ${container name or container id}//logsforcontainerrunninginthebackground (detached mode)dockerrun-eAPP_COLOR=greensimple-webapp-colordockerrun-eAPP_COLOR=bluesimple-webapp-color//-eforenvironmentvariabledockerrun-p38282:8080--nameblue-app-eAPP_COLOR=blue-dkodekloud/simple-webapp//8080to38282//namecontainer:blue-app//envAPP_COLOR=blue//detachedmodeofimageskodekloud/simple-webapp//Toknowtheenvfieldfromwithinablue-appcontainer,//rundockerexec-itblue-appenv
After creating API server using Docker container, we can give this folder with Dockerfile to anyone and as long as they have Docker, they can simply run this folder on any machine that we want.
When you run an image, it exit immediately. Why? Because container is not supposed to host an operating system (like VM). It just run specific task or process such as instance of web server or application server or database, etc. Once the task is complete, the container exits. Only lives as long as the process inside it is alive.