{"id":128619,"date":"2025-12-02T16:27:12","date_gmt":"2025-12-02T16:27:12","guid":{"rendered":"\/in\/tutorials\/how-to-create-docker-container"},"modified":"2026-03-10T10:22:17","modified_gmt":"2026-03-10T10:22:17","slug":"how-to-create-docker-container","status":"publish","type":"post","link":"\/in\/tutorials\/how-to-create-docker-container","title":{"rendered":"How to create a Docker container for efficient application management"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p>Docker containers let you efficiently manage applications across different environments. Continue reading to learn how to create a Docker container and unlock its full potential for streamlined development and deployment.<\/p><p>Creating a Docker container is a simple process:<\/p><ol class=\"wp-block-list\">\n<li><strong>Get a Docker image<\/strong>. An image is a blueprint containing all the necessary code, libraries, and dependencies, which you can download from a public registry like Docker Hub.<\/li>\n\n\n\n<li><strong>Write a Dockerfile<\/strong>. If you need a custom image, write a Dockerfile &ndash; a simple text file with instructions for Docker on how to build your image.<\/li>\n\n\n\n<li><strong>Create the container<\/strong>. Using the image, you&rsquo;ll run a command to create a live, running instance called a container.<\/li>\n\n\n\n<li><strong>Manage the container<\/strong>. Once your container is running, you can manage its lifecycle with commands to start, stop, and monitor it.<\/li>\n<\/ol><p class=\"has-text-align-center\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Docker-Cheat-Sheet.pdf\" target=\"_blank\" rel=\"noopener\">Download free docker cheat sheet<\/a><\/p><p>\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-what-is-a-docker-container\">What is a Docker container?<\/h2><p>A Docker container is a <strong>lightweight, standalone software package that includes everything needed to run an application: code, libraries, dependencies, and runtime<\/strong>.<\/p><p>Just as a physical container can be moved from a ship to a train to a truck without changing its contents, a Docker container lets you move an app from a developer&rsquo;s laptop to a testing environment and into production without any changes.<\/p><p>This solves the classic &ldquo;it works on my machine&rdquo; problem.<\/p><p>For example, you can run a MySQL container to provide a portable database or a Node.js container for web apps.<\/p><p>Containers are based on Docker images, which act as blueprints. Each time you run an image, Docker creates a new container instance. Check out our guide on <a href=\"\/in\/tutorials\/docker-image-vs-container\">Docker image vs container<\/a> to learn about their differences.<\/p><h2 class=\"wp-block-heading\" id=\"h-prerequisites\">Prerequisites<\/h2><p>Before you start creating containers, make sure you have:<\/p><ul class=\"wp-block-list\">\n<li><strong>A server or local machine<\/strong>. This guide uses an <strong>Ubuntu 24.04 Server<\/strong>, but the commands will work on most modern Linux distributions.<\/li>\n\n\n\n<li><strong>Docker installed<\/strong>. Make sure it&rsquo;s running on your system. If you need help, follow our tutorial on <a href=\"\/in\/tutorials\/install-docker-on-ubuntu\">how to install Docker on Ubuntu<\/a>.<\/li>\n\n\n\n<li><strong>Basic command-line knowledge<\/strong>. Familiarity with navigating directories and running basic Docker commands will be helpful.<\/li>\n<\/ul><p>For <a href=\"\/in\/vps\/docker-hosting\">Hostinger&rsquo;s Docker VPS<\/a> customers, Docker and all its required components are automatically installed during your server setup.<\/p><p>If you own one of our regular VPS plans, don&rsquo;t worry. You can set it up yourself in just a few clicks:<\/p><ol class=\"wp-block-list\">\n<li>Log in to hPanel with your Hostinger account, then navigate to <strong>VPS &rarr; Manage<\/strong>.<\/li>\n\n\n\n<li>Select <strong>OS &amp; Panel &rarr; Operating System<\/strong> from your VPS dashboard&rsquo;s left sidebar.<\/li>\n\n\n\n<li>Scroll down to the <strong>Change OS<\/strong> section, type &ldquo;Docker&rdquo; in the search box, and select it.<\/li>\n\n\n\n<li>Follow the on-screen instructions and wait around <strong>five minutes<\/strong> for the process to finish.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e25dca0e348\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/04\/hpanel-vps-operating-system-docker-highlighted-1024x601.png\" alt=\"The Docker template in hPanel's VPS\" class=\"wp-image-132989\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-large\"><a href=\"\/in\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner-1024x300.png\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner.png 1024w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-300x88.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-150x44.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-768x225.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-how-to-create-a-docker-container\">How to create a Docker container<\/h2><p>Creating a Docker container involves four main steps. Below, we&rsquo;ll cover everything from getting a base image to running and managing your new container.<\/p><h3 class=\"wp-block-heading\" id=\"h-1-build-a-docker-image\">1. Build a Docker image<\/h3><p>A blueprint for your container, a Docker image contains the necessary files and instructions for running your app. You can create images from scratch, but it&rsquo;s much faster to use official, pre-built images available on <a href=\"https:\/\/hub.docker.com\" target=\"_blank\" rel=\"noopener\">Docker Hub<\/a>.<\/p><ol class=\"wp-block-list\">\n<li>Create a directory to store your app, then navigate to it:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">mkdir myapp &amp;&amp; cd myapp<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Pull an image from Docker Hub to your local system using the docker pull command followed by the image name:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker pull image_name<\/pre><p>For example, to get the latest MySQL image:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker pull mysql<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Once the download is complete, list all the images on your system to confirm it&rsquo;s there:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker images<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e25dca11326\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/04\/terminal-docker-pull-images-1024x525.png\" alt=\"A terminal output after running the docker pull and images commands\" class=\"wp-image-132993\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-2-write-a-dockerfile\">2. Write a Dockerfile<\/h3><p>If a pre-built image doesn&rsquo;t fit your needs, you can create a custom one using a Dockerfile. This is a text document that contains all the commands needed to assemble an image.<\/p><p><div><p class=\"important\">Important! This step is only necessary for custom apps. If you&rsquo;re using a pre-built image like MySQL directly, skip to the next step.<\/p><\/div>\n\n\n\n<\/p><ol class=\"wp-block-list\">\n<li>Create a Dockerfile using the <a href=\"\/in\/tutorials\/how-to-install-and-use-nano-text-editor\">nano text editor<\/a>:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">nano Dockerfile<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Paste the following sample Dockerfile content inside the file. This will create a basic HTTP Python server.<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Use the official Python image from Docker Hub\nFROM python:3.8-slim\n\n# Set the working directory in the container\nWORKDIR \/app\n\n# Install curl (just as an example of using RUN)\nRUN apt-get update &amp;&amp; apt-get install -y curl\n\n# Expose the port that the HTTP server will run on\nEXPOSE 8000\n\n# Start a simple HTTP server when the container runs\nCMD [\"python\", \"-m\", \"http.server\", \"8000\"]<\/pre><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/04\/terminal-nano-dockerfile-scaled.png\"><img decoding=\"async\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/04\/terminal-nano-dockerfile-1024x572.png\" alt=\"A sample Dockerfile content\" class=\"wp-image-132996\"><\/a><\/figure><\/div><p>Here&rsquo;s a quick breakdown of the key commands:<\/p><ul class=\"wp-block-list\">\n<li><strong>FROM<\/strong>. Specifies the base image to build upon.<\/li>\n\n\n\n<li><strong>RUN<\/strong>. Executes a command during the build process, such as installing software.<\/li>\n\n\n\n<li><strong>CMD<\/strong>. Provides the default command for an executing container.<\/li>\n<\/ul><ol start=\"3\" class=\"wp-block-list\">\n<li>Once you&rsquo;re done, save the file and exit <strong>nano<\/strong> by pressing <strong>Ctrl + X &rarr; Y &rarr; Enter<\/strong>.<\/li>\n<\/ol><h3 class=\"wp-block-heading\" id=\"h-3-create-the-docker-container\">3. Create the Docker container<\/h3><p>Now it&rsquo;s time to create the container. You&rsquo;ll use two key commands: <strong>docker build<\/strong> to create an image from a Dockerfile, and <strong>docker run<\/strong> to create and start a container from an image.<\/p><ol class=\"wp-block-list\">\n<li>If you created a Dockerfile, run <strong>docker build<\/strong> with the <strong>-t<\/strong> flag to tag the image with a name. For example:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker build -t my-python-server .<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e25dca1420e\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/04\/terminal-docker-build-1024x589.png\" alt=\"A terminal output after running the docker build command\" class=\"wp-image-132999\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><ol start=\"2\" class=\"wp-block-list\">\n<li>With your image ready (whether you built it or pulled it), use <strong>docker run<\/strong> to create the container. Here&rsquo;s how you would run your custom Python image:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker run --name my-python-container -d -p 8000:8000 my-python-server<\/pre><p>If you want to run the MySQL image you pulled earlier, use:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker run --name my-mysql-container -e MYSQL_ROOT_PASSWORD=my-secret-password -d mysql<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e25dca15e2a\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/04\/terminal-docker-run-1024x77.png\" alt=\"A terminal output after running the docker run commands\" class=\"wp-image-133000\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>For both commands, <strong>&ndash;name<\/strong> assigns a custom name for easier management, and <strong>-d<\/strong> runs the container in detached mode (in the background).<\/p><h3 class=\"wp-block-heading\" id=\"h-4-run-and-manage-containers\">4. Run and manage containers<\/h3><p>Once your container is running, you can manage it with several useful commands.<\/p><ul class=\"wp-block-list\">\n<li>List running containers:<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker ps<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e25dca179fb\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/04\/terminal-docker-ps-1024x53.png\" alt=\"A terminal output after running the docker ps command\" class=\"wp-image-133003\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><ul class=\"wp-block-list\">\n<li>View container logs for debugging:<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker logs my-mysql-container<\/pre><ul class=\"wp-block-list\">\n<li>Stop a container:<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker stop my-mysql-container<\/pre><ul class=\"wp-block-list\">\n<li>Check real-time resource usage:<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker stats<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e25dca19458\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/04\/terminal-docker-stats-1024x59.png\" alt=\"A terminal output after running the docker stats command\" class=\"wp-image-133004\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>For advanced container management, use the <a href=\"\/in\/tutorials\/docker-exec-command\">docker exec command<\/a>. It lets you execute a command inside an already running container without disrupting its operation.<\/p><h2 class=\"wp-block-heading\" id=\"h-why-use-docker-containers\">Why use Docker containers<\/h2><p>Docker containers offer significant advantages for developers and businesses by improving how applications are built, shipped, and run. Here are the main benefits:<\/p><ul class=\"wp-block-list\">\n<li><strong>Portability<\/strong>. Containers bundle an app with its dependencies so that it runs consistently across any environment, from a local machine to the cloud.<\/li>\n\n\n\n<li><strong>Cost-effectiveness<\/strong>. Containers share the host system&rsquo;s kernel, making them much more lightweight than traditional virtual machines (VMs). This means you can run more containers on a single server, maximizing resources.<\/li>\n\n\n\n<li><strong>Scalability<\/strong>. You can quickly create multiple instances of a container to handle increased load, making it easy to scale apps up or down as needed.<\/li>\n\n\n\n<li><strong>Speed<\/strong>. You can create Docker containers in seconds, speeding up development, testing, and deployment cycles.<\/li>\n\n\n\n<li><strong>Isolation<\/strong>. Each container runs in an isolated environment, preventing conflicts between apps and their dependencies.<\/li>\n<\/ul><p>For a closer look at how Docker containers power real-world applications, check out the top <a href=\"\/in\/tutorials\/docker-use-cases\">Docker use cases<\/a>.<\/p><h2 class=\"wp-block-heading\" id=\"h-what-are-some-docker-container-best-practices\">What are some Docker container best practices?<\/h2><p>Following best practices ensures your Docker containers are efficient, secure, and easy to manage. These are especially useful in scenarios such as hosting sites and deploying apps.<\/p><ul class=\"wp-block-list\">\n<li><strong>Keep images lightweight<\/strong>. Start with a minimal base image, such as <strong>alpine<\/strong>. In your Dockerfile, combine <strong>RUN<\/strong> commands and clean up temporary files in the same layer to minimize image size. For instance:<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">RUN apt-get update &amp;&amp; apt-get install -y python3 &amp;&amp; rm -rf \/var\/lib\/apt\/lists\/*<\/pre><ul class=\"wp-block-list\">\n<li><strong>Use official images<\/strong>. Whenever possible, use official images from Docker Hub. They are regularly updated, scanned for security vulnerabilities, and optimized for performance.<\/li>\n\n\n\n<li><strong>Run containers as a non-root user<\/strong>. By default, containers run with root privileges, which poses a security risk. Create a dedicated user in your Dockerfile and use the <strong>USER<\/strong> instruction to run the app with fewer permissions.<\/li>\n\n\n\n<li><strong>Secure sensitive information<\/strong>. Avoid hardcoding sensitive data, such as API keys, directly in your Dockerfile. Use environment variables (<strong>-e<\/strong> flag) or Docker secrets to manage sensitive information securely.<\/li>\n\n\n\n<li><strong>Limit container resources<\/strong>. Prevent a single container from consuming all the host&rsquo;s resources by setting CPU and memory limits when you run it:<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker run --cpus=0.5 --memory=500m image-name<\/pre><h2 class=\"wp-block-heading\" id=\"h-next-steps-for-using-docker-containers\">Next steps for using Docker containers<\/h2><p>We&rsquo;ve covered how to create, manage, and optimize Docker containers, which let you build more consistent, portable, and efficient applications. This foundation streamlines the development lifecycle and makes software deployment more reliable.<\/p><p>When you start working with multiple containers for a single app, consider exploring container orchestration. Tools like <strong>Docker Swarm<\/strong> and <strong>Kubernetes<\/strong> automate the deployment, scaling, and management of containerized apps.<\/p><p><a href=\"\/in\/tutorials\/how-to-create-docker-swarm\">Docker Swarm<\/a> offers a simple setup and tight integration with Docker, and it works best for small to medium-sized clusters. <a href=\"\/in\/tutorials\/kubernetes-tutorial\">Kubernetes<\/a>, on the other hand, provides greater power and features, making it ideal for large-scale, production-grade deployments with advanced scheduling and self-healing capabilities.<\/p><p>The choice is yours: use Swarm for a lightweight, easy-to-use solution, or choose Kubernetes for maximum flexibility and scalability.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Docker containers let you efficiently manage applications across different environments. Continue reading to learn how to create a Docker container and unlock its full potential for streamlined development and deployment. Creating a Docker container is a simple process: What is a Docker container? A Docker container is a lightweight, standalone software package that includes everything [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/in\/tutorials\/how-to-create-docker-container\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":115,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"","rank_math_description":"","rank_math_focus_keyword":"","footnotes":""},"categories":[22642,22640],"tags":[],"class_list":["post-128619","post","type-post","status-publish","format-standard","hentry","category-pre-installed-applications","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-create-docker-container","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-create-docker-container","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-create-docker-container","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-create-docker-container","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-create-docker-container","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-create-docker-container","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-create-docker-container","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-create-docker-container","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/128619","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/users\/115"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/comments?post=128619"}],"version-history":[{"count":0,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/128619\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/media?parent=128619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/categories?post=128619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/tags?post=128619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}