{"id":4323,"date":"2019-11-07T05:39:23","date_gmt":"2019-11-07T05:39:23","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=4323"},"modified":"2026-03-10T09:30:18","modified_gmt":"2026-03-10T09:30:18","slug":"run-docker-wordpress","status":"publish","type":"post","link":"\/ca\/tutorials\/run-docker-wordpress","title":{"rendered":"How to install WordPress on Ubuntu using Docker"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p>Installing WordPress on an Ubuntu virtual private server (VPS) commonly requires LAMP (Linux, Apache, MySQL, PHP). However, you can also set up the platform using Docker, a containerization tool that packages applications and their dependencies together.<\/p><p>Using Docker, WordPress installation becomes simpler, as it runs from pre-built images containing all necessary components. This approach offers several benefits: it&rsquo;s modular, easy to update and scale, and quick to redeploy should you need a new instance.<\/p><p>In this article, we&rsquo;ll explain how to install WordPress on Ubuntu using Docker. You&rsquo;ll learn each step, from preparing prerequisites to managing WordPress as a containerized content management system (CMS).<\/p><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-prerequisites-for-installing-wordpress-with-docker\">Prerequisites for installing WordPress with Docker<\/h2><p>Before installing WordPress on Docker, make sure you have a VPS running a recent version of Ubuntu, such as <strong>22.04<\/strong> or later, to avoid compatibility issues.<\/p><p>Your server should also offer full root access to prevent permission errors when modifying system files. Additionally, <a href=\"\/ca\/tutorials\/dns\/how-to-point-domain-to-vps\">point a domain name to your VPS<\/a> so your WordPress website will be accessible to the public.<\/p><p>If you don&rsquo;t have a VPS, we suggest getting a <a href=\"\/ca\/vps\/docker-hosting\">Hostinger Docker VPS plan<\/a>. Since Docker and WordPress are relatively lightweight, our <strong>KVM 1<\/strong> plan &ndash; with a single-core CPU, <strong>4 GB<\/strong> of RAM, and <strong>50 GB<\/strong> of storage &ndash; should be sufficient. You can upgrade to a higher-tier plan if you need more resources as your site grows.<\/p><p>With Hostinger, you can connect to your VPS as root directly from your web browser, making the installation process more efficient.<\/p><p>If you encounter difficulties during setup, our <strong>Kodee AI assistant<\/strong> is available to guide you through managing your WordPress instance. Simply type your questions or describe your needs, and Kodee will write a step-by-step guide for you.<\/p><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-large\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-vps-hosting\" href=\"\/ca\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" 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\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-how-to-install-wordpress-with-docker-compose\">How to install WordPress with Docker Compose<\/h2><p>Follow these steps to install WordPress using Docker. Before proceeding, access your VPS command-line interface (CLI) <a href=\"\/ca\/tutorials\/how-to-use-putty-ssh\">using the PuTTY SSH client<\/a> or terminal. Alternatively, use <strong>Hostinger Browser terminal<\/strong> if you need a simpler solution.<\/p><h3 class=\"wp-block-heading\" id=\"h-1-install-docker-and-docker-compose\">1. Install Docker and Docker Compose<\/h3><p>Hostinger users can install Docker and Docker Compose in a few clicks without commands using the preconfigured VPS template. This method is simpler and suitable for beginners.<\/p><p>    <p class=\"warning\">\n        <strong>Warning!<\/strong> Installing a new VPS template will wipe your data. Back up important files before proceeding.    <\/p>\n    \n\n\n\n<\/p><p>To do so, simply open your VPS management page on <strong>hPanel<\/strong> and navigate to <strong>OS &amp; Panel<\/strong> &rarr; <strong>Operating System<\/strong>. Select <strong>Docker <\/strong>and click <strong>Change OS<\/strong>.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e1da347d3d0\"}' 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=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/11\/hpanel-vps-operating-system-docker-highlighted-1024x253.png\" alt=\"The Docker template in VPS' Operating System page of hPanel\"><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>If you want more flexibility when configuring the tool, <a href=\"\/ca\/tutorials\/how-to-install-docker-on-ubuntu\">install Docker<\/a> and Docker Compose using commands.<\/p><p>Now, verify if Docker and Docker Compose are configured correctly using the following commands:<\/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 --version\ndocker-compose --version<\/pre><p>If these tools work properly, your CLI will output their version number:<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e1da347eb21\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"815\" height=\"132\" 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=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/11\/terminal-outputs-docker-and-docker-compose-version.png\" alt=\"Terminal outputs Docker and Docker Compose version\" class=\"wp-image-118458\"  sizes=\"auto, (max-width: 815px) 100vw, 815px\" \/><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-set-up-your-project-directory\">2. Set up your project directory<\/h3><p>Create a new project directory to house all your Docker and WordPress files using this command:<\/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=\"\">mkdir wordpress<\/pre><p>By default, the command will create the <strong>wordpress <\/strong>folder in your current user&rsquo;s home directory. You can create it in another location or use a different name.<\/p><p>Then, open the folder using the command below:<\/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=\"\">cd wordpress<\/pre><p>Once inside, you can start setting up Docker and WordPress.<\/p><h3 class=\"wp-block-heading\" id=\"h-3-create-a-docker-compose-file\">3. Create a Docker Compose file<\/h3><p>The <strong>Docker Compose file<\/strong> provides information about software components to install in your container. In this case, it specifies the configuration for WordPress and the database application.<\/p><p>To create a Docker Compose file, run the following command:<\/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=\"\">sudo nano docker-compose.yml<\/pre><p>Paste the following configuration. Replace the username, password, and database name with your desired value.<\/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=\"\">version: \"3\" \nservices:\n  db:\n    image: mysql:latest\n    restart: always\n    environment:\n      MYSQL_ROOT_PASSWORD: MySQLRootPassword\n      MYSQL_DATABASE: MySQLDatabaseName\n      MYSQL_USER: MySQLUsername\n      MYSQL_PASSWORD: MySQLUserPassword\n\n  wordpress:\n    depends_on:\n      - db\n    image: wordpress:latest\n    restart: always\n    ports:\n      - \"80:80\"\n    environment:\n      WORDPRESS_DB_HOST: db:3306\n      WORDPRESS_DB_USER: MySQLUsername\n      WORDPRESS_DB_PASSWORD: MySQLUserPassword\n      WORDPRESS_DB_NAME: MySQLDatabaseName\n    volumes:\n      - \".\/:\/var\/www\/html\"\n\n  phpmyadmin:\n    image: phpmyadmin\/phpmyadmin\n    restart: always\n    ports:\n      - \"8080:80\"\n    environment:\n      PMA_HOST: db\n      PMA_USER: MySQLUsername\n      PMA_PASSWORD: MySQLUserPassword\n\nvolumes:\n  mysql: {}<\/pre><p>Save the changes and return to the main shell by pressing<strong> Ctrl + X<\/strong> &rarr; <strong>Y<\/strong> &rarr; <strong>Enter<\/strong>. <\/p><h3 class=\"wp-block-heading\" id=\"h-4-start-the-docker-container\">4. Start the Docker container<\/h3><p>Run Docker Compose using this command to install and launch WordPress in a container. Remember that it only works when you are inside the project directory:<\/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-compose up -d<\/pre><p>Docker Compose will pull images from<strong> <\/strong><a href=\"https:\/\/docs.docker.com\/docker-hub\" target=\"_blank\" rel=\"noopener\">Docker Hub<\/a> as specified in your <strong>YAML <\/strong>file, configure the container, and set up the network connection. Depending on your internet speed, this setup process might take a few minutes.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e1da348102d\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"888\" height=\"148\" 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=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/11\/terminal-shows-docker-has-completed-wordpress-installation.png\" alt=\"Terminal shows Docker has competed WordPress installation\" class=\"wp-image-118459\"  sizes=\"auto, (max-width: 888px) 100vw, 888px\" \/><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>Once finished, you should see the <strong>Done <\/strong>status and return to the main shell.<\/p><h3 class=\"wp-block-heading\" id=\"h-5-access-the-wordpress-installation\">5. Access the WordPress installation<\/h3><p>With your Docker container up and running, you can now access the new WordPress installation through your web browser. Since your domain name is already pointed to the VPS, simply enter it in the browser&rsquo;s address bar.<\/p><p>This will take you to the WordPress setup wizard. Choose your preferred language and click <strong>Continue<\/strong>.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e1da348228a\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"601\" height=\"1024\" 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=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/11\/wordpress-setup-wizard-601x1024.png\" alt=\"The WordPress setup wizard\" class=\"wp-image-118460\"  sizes=\"auto, (max-width: 601px) 100vw, 601px\" \/><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>Next, fill in the necessary information about your site, including the site title, username, password, and email address. Once complete, hit <strong>Install WordPress<\/strong>.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e1da3483303\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1013\" height=\"1024\" 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=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/11\/wordpress-welcome-install-wordpress-highlighted-1013x1024.png\" alt=\"The Install WordPress button in the WordPress Welcome page\" class=\"wp-image-118461\"  sizes=\"auto, (max-width: 1013px) 100vw, 1013px\" \/><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>After that, click <strong>Log In<\/strong> to enter the WordPress dashboard. Use the credentials you just created to access your admin panel.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e1da34844e3\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"521\" 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=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/11\/wordpress-admin-dashboard-1024x521.png\" alt=\"The WordPress admin dashboard\" class=\"wp-image-118462\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><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-6-customize-your-docker-configuration\">6. Customize your Docker configuration<\/h3><p>For production environments, you&rsquo;ll need additional configurations so that your WordPress site is secure and optimized for performance. Below are key customizations to deploy WordPress using Docker:<\/p><p><strong>Using environment files<\/strong><\/p><p>To protect sensitive data, avoid hardcoding credentials like database usernames and passwords in your Docker Compose file. Instead, store these values in an environment file (<strong>.env<\/strong>).<\/p><p>In your <strong>wordpress<\/strong> directory, create a <strong>.env<\/strong> file:<\/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=\"\">nano .env<\/pre><p>Define your WordPress database credentials in the <strong>.env<\/strong> file, replacing placeholders with your own values:<\/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=\"\">MYSQL_ROOT_PASSWORD=MySQLRootPassword\nMYSQL_DATABASE=MySQLDatabaseName\nMYSQL_USER=MySQLUsername\nMYSQL_PASSWORD=MySQLUserPassword<\/pre><p>Save the file, then update the <strong>docker-compose.yml<\/strong> file to use these environment variables:<\/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=\"\">db:\n  image: mysql:latest\n  restart: always\n  environment:\n    MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}\n    MYSQL_DATABASE: ${MYSQL_DATABASE}\n    MYSQL_USER: ${MYSQL_USER}\n    MYSQL_PASSWORD: ${MYSQL_PASSWORD}<\/pre><p>Save the changes and restart Docker Compose to apply the new configurations:<\/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-compose up -d<\/pre><p><strong>Obtaining SSL certificates<\/strong><\/p><p>An SSL certificate is important for protecting user data and improving search engine rankings. To enable automatic SSL certificates, <a href=\"\/ca\/tutorials\/how-to-set-up-nginx-reverse-proxy\">add an NGINX proxy<\/a> with Let&rsquo;s Encrypt in your <strong>docker-compose.yml<\/strong> file:<\/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=\"\">services:\n  nginx-proxy:\n    image: jwilder\/nginx-proxy\n    container_name: nginx-proxy\n    ports:\n      - \"80:80\"\n      - \"443:443\"\n    volumes:\n      - \/var\/run\/docker.sock:\/tmp\/docker.sock:ro\n  letsencrypt-nginx-proxy-companion:\n    image: jrcs\/letsencrypt-nginx-proxy-companion\n    container_name: letsencrypt\n    environment:\n      NGINX_PROXY_CONTAINER: nginx-proxy\n    volumes:\n      - \/var\/run\/docker.sock:\/var\/run\/docker.sock:ro\n      - .\/certs:\/etc\/nginx\/certs\n      - .\/vhost.d:\/etc\/nginx\/vhost.d\n      - .\/html:\/usr\/share\/nginx\/html<\/pre><p>Next, remove port mapping from the <strong>wordpress<\/strong> service to avoid conflicts with <strong>nginx-proxy<\/strong>. Also, include SSL labels by replacing <strong>your_email<\/strong> and <strong>your_domain.com<\/strong> with your actual credentials:<\/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=\"\">wordpress:\n  image: wordpress:latest\n  labels:\n    - \"VIRTUAL_HOST=your_domain.com\"\n    - \"LETSENCRYPT_HOST=your_domain.com\"\n    - \"LETSENCRYPT_EMAIL=your_email@your_domain.com\"<\/pre><p>In the same <strong>wordpress <\/strong>service, mount only the <strong>wp-content<\/strong> directory so that only necessary files are shared between the host and the container:<\/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=\"\">volumes:\n  - .\/wp-content:\/var\/www\/html\/wp-content<\/pre><p>Here&rsquo;s the final <strong>docker-compose.yml<\/strong> content after using environment variables and adding SSL support with NGINX:<\/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=\"\">version: \"3\"\n\nservices:\n  db:\n    image: mysql:latest\n    restart: always\n    environment:\n      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}\n      MYSQL_DATABASE: ${MYSQL_DATABASE}\n      MYSQL_USER: ${MYSQL_USER}\n      MYSQL_PASSWORD: ${MYSQL_PASSWORD}\n    volumes:\n      - mysql:\/var\/lib\/mysql\n\n  wordpress:\n    depends_on:\n      - db\n    image: wordpress:latest\n    restart: always\n    environment:\n      WORDPRESS_DB_HOST: db:3306\n      WORDPRESS_DB_USER: ${MYSQL_USER}\n      WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}\n      WORDPRESS_DB_NAME: ${MYSQL_DATABASE}\n    volumes:\n      - .\/wp-content:\/var\/www\/html\/wp-content\n    labels:\n      - \"VIRTUAL_HOST=your_domain.com\"\n      - \"LETSENCRYPT_HOST=your_domain.com\"\n      - \"LETSENCRYPT_EMAIL=your_email@your_domain.com\"\n\n  phpmyadmin:\n    image: phpmyadmin\/phpmyadmin\n    restart: always\n    ports:\n      - \"8080:80\"\n    environment:\n      PMA_HOST: db\n      PMA_USER: ${MYSQL_USER}\n      PMA_PASSWORD: ${MYSQL_PASSWORD}\n\n  nginx-proxy:\n    image: jwilder\/nginx-proxy\n    container_name: nginx-proxy\n    ports:\n      - \"80:80\"\n      - \"443:443\"\n    volumes:\n      - \/var\/run\/docker.sock:\/tmp\/docker.sock:ro\n      - .\/certs:\/etc\/nginx\/certs\n      - .\/vhost.d:\/etc\/nginx\/vhost.d\n      - .\/html:\/usr\/share\/nginx\/html\n\n  letsencrypt-nginx-proxy-companion:\n    image: jrcs\/letsencrypt-nginx-proxy-companion\n    container_name: letsencrypt\n    environment:\n      NGINX_PROXY_CONTAINER: nginx-proxy\n    volumes:\n      - \/var\/run\/docker.sock:\/var\/run\/docker.sock:ro\n      - .\/certs:\/etc\/nginx\/certs\n      - .\/vhost.d:\/etc\/nginx\/vhost.d\n      - .\/html:\/usr\/share\/nginx\/html\n\nvolumes:\n  mysql: {}<\/pre><p>Don&rsquo;t forget to save these changes and restart Docker Compose afterward:<\/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-compose up -d<\/pre><h3 class=\"wp-block-heading\" id=\"h-7-manage-and-scale-wordpress-with-docker\">7. Manage and scale WordPress with Docker<\/h3><p>After running WordPress in Docker for a while, scale your setup to optimize its performance and regularly back up your files to maintain data integrity. Here&rsquo;s how:<\/p><p><strong>Scaling WordPress containers<\/strong><\/p><p>As your site traffic grows, consider scaling your WordPress service to run multiple containers. It lets you evenly distribute user requests across different containers for optimal performance and uptime.<\/p><p>In your Docker Compose file, specify the desired number of replicas, such as <strong>3<\/strong>, to add more instances of your WordPress container:<\/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=\"\"> wordpress:\n    depends_on:\n      - db\n    image: wordpress:latest\n    restart: always\n    ports:\n      - \"80:80\"\n  environment:\n    WORDPRESS_DB_HOST: db:3306\n    WORDPRESS_DB_USER: ${MYSQL_USER}\n    WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}\n    WORDPRESS_DB_NAME: ${MYSQL_DATABASE}\n  volumes:\n    - \".\/:\/var\/www\/html\"\n  deploy:\n    replicas: 3<\/pre><p>Apply your changes by running:<\/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-compose up -d --scale wordpress=3<\/pre><p>Docker will now start additional WordPress containers and distribute traffic evenly between them.<\/p><p><strong>Backing up WordPress files<\/strong><\/p><p>To protect your WordPress site against data loss or corruption, you should back up both WordPress files and the database.<\/p><p>Since Docker mounts the WordPress directory as a volume, you can back up this directory using a simple command like this:<\/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=\"\">cp -r \/path\/to\/wordpress \/path\/to\/backup\/location<\/pre><p>To back up your MySQL database, run the following command. Replace <strong>[db_container_name]<\/strong>, <strong>[MYSQL_USER], [MYSQL_PASSWORD]<\/strong>, and <strong>[MYSQL_DATABASE]<\/strong> with your actual database container name and credentials:<\/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 exec [db_container_name] \/usr\/bin\/mysqldump -u [MYSQL_USER] -p[MYSQL_PASSWORD] [MYSQL_DATABASE] &amp;gt; backup.sql<\/pre><p>This command creates a database dump, which you can restore later if needed.<\/p><p>Alternatively, Hostinger VPS customers can use our built-in backup tools to easily back up and restore data. To access these features, go to <strong>Backup &amp; Monitoring &rarr; Snapshots &amp; Backups<\/strong> in your VPS dashboard&rsquo;s left sidebar.<\/p><p>Then, choose to either create a snapshot to capture your current setup or restore previous data from an automated weekly backup.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e1da3485b74\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"816\" 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=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/11\/hpanel-vps-snapshots-backups-1024x816.png\" alt=\"The Snapshots &amp; Backups menu in Hostinger's hPanel\" class=\"wp-image-118463\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><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><div class=\"protip\">\n                    <h4 class=\"title\">Manage backups with Kodee<\/h4>\n                    <p>You can list available backups and manage backup schedule by simply asking <strong>Kodee<\/strong>. For example, ask, \"List available backups on my hostname.com VPS.\"<\/p>\n                <\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>In this article, you&rsquo;ve learned how to install and configure WordPress using Docker on an Ubuntu VPS. From setting up Docker Compose to customizing for production environments, you now have a fully functional WordPress setup in a containerized environment.<\/p><p>After running WordPress using Docker, consider optimizing your site further, such as by using a content delivery network (CDN). You can also set up different Docker containers if you decide to host other applications on the same VPS.<\/p><p>If you have any questions or would like to share your experience developing WordPress websites with Docker, feel free to use the comment box below.<\/p><h2 class=\"wp-block-heading\" id=\"h-wordpress-docker-faq\">WordPress Docker FAQ<\/h2><div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1730938301692\"><h3 class=\"schema-faq-question\">What are the benefits of using Docker for WordPress?<\/h3> <p class=\"schema-faq-answer\">With Docker, you can deploy and scale your WordPress environment as needed. Docker isolates dependencies, making it easier to update, back up, and migrate your WordPress site efficiently.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1730938312113\"><h3 class=\"schema-faq-question\">Can I run multiple WordPress sites on a single server with Docker?<\/h3> <p class=\"schema-faq-answer\">Yes, Docker lets you run multiple WordPress websites on a single server by using separate containers for each site. Set up each container with unique ports, volumes, and database connections for isolation.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1730938326166\"><h3 class=\"schema-faq-question\">How do I configure a WordPress Docker container?<\/h3> <p class=\"schema-faq-answer\">To configure a WordPress Docker container, use a Docker Compose file to define services, ports, and environment variables. For sensitive data, such as database credentials, we suggest storing it in a <strong>.env<\/strong> file linked to the Compose file.<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Installing WordPress on an Ubuntu virtual private server (VPS) commonly requires LAMP (Linux, Apache, MySQL, PHP). However, you can also set up the platform using Docker, a containerization tool that packages applications and their dependencies together. Using Docker, WordPress installation becomes simpler, as it runs from pre-built images containing all necessary components. This approach offers [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ca\/tutorials\/run-docker-wordpress\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":411,"featured_media":139786,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to install WordPress on Docker","rank_math_description":"Learn how to install WordPress on Docker: 1. Install Docker 2. Set up a directory 3. Create a Compose file 4. Start the container + more.","rank_math_focus_keyword":"docker wordpress","footnotes":""},"categories":[22701,22699],"tags":[],"class_list":["post-4323","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pre-installed-applications","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/run-docker-wordpress","default":0},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/wordpress-docker","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/docker-wordpress","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/instalar-wordpress-en-docker","default":0},{"locale":"ja-JP","link":"https:\/\/www.hostinger.com\/jp\/tutorials\/run-docker-wordpress","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/run-docker-wordpress","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/run-docker-wordpress","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/run-docker-wordpress","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/instalar-wordpress-en-docker","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/instalar-wordpress-en-docker","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/instalar-wordpress-en-docker","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/wordpress-docker","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/run-docker-wordpress","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/run-docker-wordpress","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/run-docker-wordpress","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/run-docker-wordpress","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/4323","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/users\/411"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/comments?post=4323"}],"version-history":[{"count":89,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/4323\/revisions"}],"predecessor-version":[{"id":138841,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/4323\/revisions\/138841"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/media\/139786"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/media?parent=4323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/categories?post=4323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/tags?post=4323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}