<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>docker &#8211; achraf ben alaya</title>
	<atom:link href="https://achrafbenalaya.com/category/blog/docker/feed/" rel="self" type="application/rss+xml" />
	<link>https://achrafbenalaya.com</link>
	<description>Tech Blog By Achraf Ben Alaya</description>
	<lastBuildDate>Sat, 01 Jul 2023 07:47:25 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.5</generator>

<image>
	<url>/wp-content/uploads/2022/02/cropped-me-scaled-1-32x32.jpeg</url>
	<title>docker &#8211; achraf ben alaya</title>
	<link>https://achrafbenalaya.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">189072172</site>	<item>
		<title>Streamlining Website Editing on My Local Machine with Docker Compose and WordPress</title>
		<link>https://achrafbenalaya.com/2023/06/30/streamlining-website-editing-on-my-local-machine-with-docker-compose-and-wordpress/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=streamlining-website-editing-on-my-local-machine-with-docker-compose-and-wordpress</link>
					<comments>https://achrafbenalaya.com/2023/06/30/streamlining-website-editing-on-my-local-machine-with-docker-compose-and-wordpress/#comments</comments>
		
		<dc:creator><![CDATA[achraf]]></dc:creator>
		<pubDate>Fri, 30 Jun 2023 09:35:05 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[docker]]></category>
		<guid isPermaLink="false">https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/?p=1729</guid>

					<description><![CDATA[Well, it has been occupying my thoughts for the past two days, as I contemplated writing this article. I want to make it clear from the start that WordPress is not my area of expertise. My skills are primarily focused on writing posts, editing themes, and handling normal administrative tasks. A couple of days ago, [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Well, it has been occupying my thoughts for the past two days, as I contemplated writing this article. I want to make it clear from the start that WordPress is not my area of expertise. My skills are primarily focused on writing posts, editing themes, and handling normal administrative tasks.</p>
<p>A couple of days ago, I found myself with some spare time, and two specific actions came to my mind regarding my website. First, I wanted to migrate it to a different virtual machine, and secondly, I aimed to enhance the overall theme and user interface.</p>
<p>Considering that I didn&#8217;t want to experiment directly on the production environment, I decided to explore the world of WordPress on my local machine. However, I had one condition:Installing the least number of tools is my first condition. Instead, I opted to leverage Docker for testing purposes. In this article, I will guide you through the process of achieving this without the need for any external installations.</p>
<h1>Docker</h1>
<p>Docker is a platform that allows you to package and run applications in isolated environments called containers. It provides a lightweight and efficient way to deploy software, as containers are self-contained and can run consistently across different systems. Docker simplifies the process of managing dependencies and ensures that applications run smoothly in any environment, making it popular for software development, deployment, and scaling.</p>
<p>In order to install docker you can download from the official website : https://www.docker.com/</p>
<p>Now , what we want to have is wordpress + mysql toghther  , in order to have that we need to create a docker compose file , but first what is <strong>docker compose</strong> ?</p>
<p>Docker Compose is a tool that allows you to define and manage multi-container applications. It is used to specify the services, networks, and volumes required for your application&#8217;s containers to work together. With Docker Compose, you can describe your application&#8217;s infrastructure in a YAML file, including details like container images, environment variables, networking configurations, and dependencies between containers. By using Docker Compose, you can easily spin up and manage complex applications with multiple containers, simplifying the process of running and orchestrating your application&#8217;s various components.</p>
<p>So , in our project we are going to need to have two containers , one for my sql and oen for wordpress .</p>
<h1><strong>Docker compose File</strong></h1>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">version: '3'

services:
  db:
    image: mysql:latest

    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - 3000:80
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress

</pre>
<p>&nbsp;</p>
<p>The provided YAML file is a Docker Compose file that defines the configuration for a multi-container application. Let&#8217;s break down the role of each section within this file:</p>
<p>1. `version: &#8216;3&#8217;`: Specifies the version of the Docker Compose file format being used. In this case, it is version 3.</p>
<p>2. `services`: This section defines the individual services (containers) .</p>
<p>a. `db`: This service represents a MySQL database container.<br />
&#8211; `image: mysql:latest`: Specifies the Docker image to use for the MySQL container, in this case, the latest version.<br />
&#8211; `volumes`: Mounts a Docker volume named `db_data` to the container&#8217;s `/var/lib/mysql` directory. This allows data to persist even if the container is recreated.<br />
&#8211; `restart: always`: Specifies that the container should be automatically restarted if it stops.<br />
&#8211; `environment`: Sets environment variables within the container. Here, it defines the root password, database name, user, and password for MySQL.</p>
<p>b. `wordpress`: This service represents a WordPress container.<br />
&#8211; `depends_on`: Specifies that the WordPress container depends on the `db` service, ensuring that the database container is started before the WordPress container.<br />
&#8211; `image: wordpress:latest`: Specifies the Docker image to use for the WordPress container, using the latest version.<br />
&#8211; `ports`: Maps port 80 of the container to port 3000 on the host system, allowing access to the WordPress application.<br />
&#8211; `restart: always`: Indicates that the container should be automatically restarted if it stops.<br />
&#8211; `environment`: Sets environment variables within the container. Here, it configures the WordPress container to connect to the MySQL container using the specified host, user, password, and database name.</p>
<p>Overall, this Docker Compose file defines two services: a MySQL database container (`db`) and a WordPress container (`wordpress`). The configuration ensures that the WordPress container can communicate with the MySQL container, allowing you to run a WordPress application with a MySQL database using Docker.</p>
<p>In order to test we can use the following command :</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="bootstrap4">docker-compose up -d</pre>
<p>The command `docker-compose up -d` is used to start the services defined in the Docker Compose file in detached mode.</p>
<p>Here&#8217;s a breakdown of the command:</p>
<p>&#8211; `docker-compose`: Refers to the Docker Compose command-line interface.<br />
&#8211; `up`: Specifies that you want to start the defined services.<br />
&#8211; `-d`: Stands for &#8220;detached&#8221; mode, which means the services will run in the background, and the terminal will be available for other commands.</p>
<p>When you run `docker-compose up -d`, Docker Compose reads the configuration from the `docker-compose.yml` file in the current directory and starts the associated containers as defined in the file. The services will be started in the background, and you will see the container names or IDs printed to the console.</p>
<p>Using the `-d` flag allows you to start the services and continue using the terminal for other tasks without being attached to the containers&#8217; logs or output.</p>
<p>after runing the command we can see the below containers up and runing<br />
<a href="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/3.png"><img fetchpriority="high" decoding="async" class="aligncenter size-full wp-image-1733" src="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/3.png" alt="" width="946" height="103" srcset="/wp-content/uploads/2023/06/3.png 946w, /wp-content/uploads/2023/06/3-300x33.png 300w, /wp-content/uploads/2023/06/3-768x84.png 768w, /wp-content/uploads/2023/06/3-750x82.png 750w" sizes="(max-width: 946px) 100vw, 946px" /></a> <a href="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/11.png"><img decoding="async" class="aligncenter size-full wp-image-1734" src="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/11.png" alt="" width="1224" height="474" srcset="/wp-content/uploads/2023/06/11.png 1224w, /wp-content/uploads/2023/06/11-300x116.png 300w, /wp-content/uploads/2023/06/11-1024x397.png 1024w, /wp-content/uploads/2023/06/11-768x297.png 768w, /wp-content/uploads/2023/06/11-750x290.png 750w, /wp-content/uploads/2023/06/11-1140x441.png 1140w" sizes="(max-width: 1224px) 100vw, 1224px" /></a>and if we visit http://localhost:3000/<br />
<a href="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/1-1.png"><img decoding="async" class="aligncenter size-full wp-image-1732" src="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/1-1.png" alt="" width="1704" height="830" srcset="/wp-content/uploads/2023/06/1-1.png 1704w, /wp-content/uploads/2023/06/1-1-300x146.png 300w, /wp-content/uploads/2023/06/1-1-1024x499.png 1024w, /wp-content/uploads/2023/06/1-1-768x374.png 768w, /wp-content/uploads/2023/06/1-1-1536x748.png 1536w, /wp-content/uploads/2023/06/1-1-750x365.png 750w, /wp-content/uploads/2023/06/1-1-1140x555.png 1140w" sizes="(max-width: 1704px) 100vw, 1704px" /></a>now we need to just follow the steps to install it .</p>
<p><a href="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/4.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1738" src="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/4.png" alt="" width="1442" height="945" srcset="/wp-content/uploads/2023/06/4.png 1442w, /wp-content/uploads/2023/06/4-300x197.png 300w, /wp-content/uploads/2023/06/4-1024x671.png 1024w, /wp-content/uploads/2023/06/4-768x503.png 768w, /wp-content/uploads/2023/06/4-750x492.png 750w, /wp-content/uploads/2023/06/4-1140x747.png 1140w" sizes="(max-width: 1442px) 100vw, 1442px" /></a></p>
<h1>Taking a backup from the official website</h1>
<p>There are several methods available for taking backups and managing them within WordPress. However, based on my limited expertise with WordPress, I highly recommend using the &#8220;All-in-One WP Migration&#8221; plugin, which can be found at https://servmask.com/.</p>
<p>The &#8220;All-in-One WP Migration&#8221; plugin offers a comprehensive solution for handling backups within WordPress. It simplifies the process of creating backups, allowing you to effortlessly migrate your website from one location to another. With this plugin, you can easily export your entire WordPress installation, including the database, media files, themes, plugins, and more, into a single file. This file can then be imported into a different WordPress installation, making it an efficient and convenient tool for website backups and migrations.</p>
<p>By utilizing the &#8220;All-in-One WP Migration&#8221; plugin, you can ensure the safety and security of your WordPress website, making it easier to restore or move your site when needed.</p>
<p><a href="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/1.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1731" src="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/1.png" alt="" width="402" height="763" srcset="/wp-content/uploads/2023/06/1.png 402w, /wp-content/uploads/2023/06/1-158x300.png 158w" sizes="(max-width: 402px) 100vw, 402px" /></a>now when I click that ,a file with <a id="file-link" tabindex="0" role="link" href="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/ai1wm-backups/achrafbenalaya.com-20230624-211727-784.wpress">.wpress</a> extension will be downloaded and you need to install the same one on the local version in order to import it .</p>
<h1>Importing the backup on the local environment</h1>
<p>Now let&#8217;s follow the below step in order to import our file :</p>
<p><a href="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/5.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1735" src="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/5.png" alt="" width="1886" height="594" srcset="/wp-content/uploads/2023/06/5.png 1886w, /wp-content/uploads/2023/06/5-300x94.png 300w, /wp-content/uploads/2023/06/5-1024x323.png 1024w, /wp-content/uploads/2023/06/5-768x242.png 768w, /wp-content/uploads/2023/06/5-1536x484.png 1536w, /wp-content/uploads/2023/06/5-750x236.png 750w, /wp-content/uploads/2023/06/5-1140x359.png 1140w" sizes="(max-width: 1886px) 100vw, 1886px" /></a> <a href="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/6.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1736" src="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/6.png" alt="" width="1596" height="732" srcset="/wp-content/uploads/2023/06/6.png 1596w, /wp-content/uploads/2023/06/6-300x138.png 300w, /wp-content/uploads/2023/06/6-1024x470.png 1024w, /wp-content/uploads/2023/06/6-768x352.png 768w, /wp-content/uploads/2023/06/6-1536x704.png 1536w, /wp-content/uploads/2023/06/6-750x344.png 750w, /wp-content/uploads/2023/06/6-1140x523.png 1140w" sizes="(max-width: 1596px) 100vw, 1596px" /></a><br />
<a href="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/7.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1737" src="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/7.png" alt="" width="1829" height="880" srcset="/wp-content/uploads/2023/06/7.png 1829w, /wp-content/uploads/2023/06/7-300x144.png 300w, /wp-content/uploads/2023/06/7-1024x493.png 1024w, /wp-content/uploads/2023/06/7-768x370.png 768w, /wp-content/uploads/2023/06/7-1536x739.png 1536w, /wp-content/uploads/2023/06/7-750x361.png 750w, /wp-content/uploads/2023/06/7-1140x548.png 1140w" sizes="(max-width: 1829px) 100vw, 1829px" /></a>This problem that we have is because wordpress have limit to upload maximum of 2 MB file and in my case it was 700 MB , let&#8217;s modify our docker compose file in order to modify the uploads ini file rules .</p>
<p>first , let&#8217;s modify our yaml file :</p>
<pre class="EnlighterJSRAW" data-enlighter-language="yaml">version: '3'

services:
  db:
    image: mysql:latest
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - 3000:80
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
      - ./uploads:/var/www/html/wp-content/uploads
volumes:
  db_data:
  uploads:
</pre>
<p>and in the same directory let&#8217;s create the <strong>uploads.ini</strong> file that will replace the original one</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">file_uploads = On
memory_limit = 1024M
upload_max_filesize = 1024M
post_max_size = 1024M
max_execution_time = 600
</pre>
<p>The provided `upload.ini` file contains configuration settings for handling file uploads in a WordPress environment. Let&#8217;s break down each directive and its purpose:</p>
<p>1. `file_uploads = On`: This directive enables file uploads on the server. It ensures that the server allows files to be uploaded through PHP scripts.</p>
<p>2. `memory_limit = 1024M`: This directive sets the maximum amount of memory that PHP can allocate for script execution. In this case, it is set to 1024 megabytes (1 gigabyte), allowing PHP to utilize more memory if necessary during file uploads.</p>
<p>3. `upload_max_filesize = 1024M`: This directive determines the maximum size of an individual file that can be uploaded. Here, it is set to 1024 megabytes (1 gigabyte), meaning files of up to this size can be uploaded.</p>
<p>4. `post_max_size = 1024M`: This directive specifies the maximum size of the entire HTTP POST request, which includes all form data, including uploaded files. It is set to 1024 megabytes (1 gigabyte), ensuring that the total request size, including uploaded files, can be as large as this limit.</p>
<p>5. `max_execution_time = 600`: This directive defines the maximum execution time, in seconds, for PHP scripts. It is set to 600 seconds (10 minutes), allowing more time for the server to process file uploads that may take longer.</p>
<p>By configuring the `upload.ini` file with these settings, you are adjusting various parameters related to file uploads in WordPress. These settings allow larger file uploads, increase memory allocation, and provide more execution time for processing uploads, ensuring a smoother experience when handling large files or performing bulk uploads in WordPress.</p>
<p>Now we need to edit remove the old volume from docker and run our command again and login to our website :<br />
<a href="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/12.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1740" src="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/12.png" alt="" width="1713" height="958" srcset="/wp-content/uploads/2023/06/12.png 1713w, /wp-content/uploads/2023/06/12-300x168.png 300w, /wp-content/uploads/2023/06/12-1024x573.png 1024w, /wp-content/uploads/2023/06/12-768x430.png 768w, /wp-content/uploads/2023/06/12-1536x859.png 1536w, /wp-content/uploads/2023/06/12-750x419.png 750w, /wp-content/uploads/2023/06/12-1140x638.png 1140w" sizes="(max-width: 1713px) 100vw, 1713px" /></a><a href="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/13.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1739" src="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2023/06/13.png" alt="" width="1693" height="855" srcset="/wp-content/uploads/2023/06/13.png 1693w, /wp-content/uploads/2023/06/13-300x152.png 300w, /wp-content/uploads/2023/06/13-1024x517.png 1024w, /wp-content/uploads/2023/06/13-768x388.png 768w, /wp-content/uploads/2023/06/13-1536x776.png 1536w, /wp-content/uploads/2023/06/13-750x379.png 750w, /wp-content/uploads/2023/06/13-1140x576.png 1140w" sizes="(max-width: 1693px) 100vw, 1693px" /></a>Now our website is being imported on local machine and we can run tests .</p>
<p>Hope this was helpful .</p>
]]></content:encoded>
					
					<wfw:commentRss>https://achrafbenalaya.com/2023/06/30/streamlining-website-editing-on-my-local-machine-with-docker-compose-and-wordpress/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1729</post-id>	</item>
		<item>
		<title>How to setup nginx reverse proxy for aspnet core apps with and without  Docker compose</title>
		<link>https://achrafbenalaya.com/2022/11/16/how-to-setup-nginx-reverse-proxy-for-aspnet-core-apps-with-and-without-docker-compose/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-setup-nginx-reverse-proxy-for-aspnet-core-apps-with-and-without-docker-compose</link>
					<comments>https://achrafbenalaya.com/2022/11/16/how-to-setup-nginx-reverse-proxy-for-aspnet-core-apps-with-and-without-docker-compose/#comments</comments>
		
		<dc:creator><![CDATA[achraf]]></dc:creator>
		<pubDate>Wed, 16 Nov 2022 21:29:19 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[docker]]></category>
		<guid isPermaLink="false">https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/?p=1471</guid>

					<description><![CDATA[Introduction First of all and before we go straight to deployment and demo let&#8217;s understand what is a reverse proxy . A reverse proxy intercepts all incoming requests and direct them to the appropriate server ,it can play the role of Load Balancer &#8221; a Traffic Cop &#8221; that will distribute the clients requests across [&#8230;]]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p>First of all and before we go straight to deployment and demo let&#8217;s understand what is a reverse proxy .</p>
<p>A reverse proxy intercepts all incoming requests and direct them to the appropriate server ,it can play the role of Load Balancer &#8221; a Traffic Cop &#8221; that will distribute the clients requests across group of servers in order to maximizes speed and capacity and making sure that no server is overloaded (in case a server is down the load balancer will redirect the traffic to the other servers ) ,more than that a reverse proxy will protect the identity of the other servers and act as a defense againsts security attacks .In this sense the reverse proxy will make sure that multiple servers can be accessed only from a single URL .</p>
<h3>Prerequisites</h3>
<ul>
<li>Visual studio or visual studio code</li>
<li>A command mine /Terminal</li>
<li>Docker installed on your system</li>
</ul>
<h2>Part 1- Without Docker Compose</h2>
<p>in this first part we will create our dotnet application that we will use now and later too , also nginx .<br />
<a href="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2022/11/dotnet.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1474" src="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2022/11/dotnet.png" alt="" width="1004" height="668" srcset="/wp-content/uploads/2022/11/dotnet.png 1004w, /wp-content/uploads/2022/11/dotnet-300x200.png 300w, /wp-content/uploads/2022/11/dotnet-768x511.png 768w, /wp-content/uploads/2022/11/dotnet-750x499.png 750w" sizes="(max-width: 1004px) 100vw, 1004px" /></a>and we will go straight to our <strong>Index.cshtml  </strong>, and edit it to be like this :</p>
<pre class="EnlighterJSRAW" data-enlighter-language="csharp">@page
@model IndexModel

@{
    ViewData["Title"] = "Home page";
    var hostname = ViewData["host"];
}

&lt;div class="text-center"&gt;
    &lt;h1 class="display-4"&gt;Welcome&lt;/h1&gt;
    &lt;p&gt;Learn about &lt;a href="https://docs.microsoft.com/aspnet/core"&gt;building Web apps with ASP.NET Core&lt;/a&gt;.&lt;/p&gt;
    &lt;p&gt;
        &lt;strong&gt;Hostname :&lt;/strong&gt; &lt;h3&gt; &lt;code&gt;@hostname&lt;/code&gt;&lt;/h3&gt;
    &lt;/p&gt;
&lt;/div&gt;
</pre>
<p>Also we will edit the <strong>Index.cshtml.cs </strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="csharp">using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Net;

namespace hostnameapp.Pages
{
    public class IndexModel : PageModel
    {
        private readonly ILogger&lt;IndexModel&gt; _logger;
        [BindProperty]
        public string? hostname { get; set; }
        public IndexModel(ILogger&lt;IndexModel&gt; logger)
        {
            _logger = logger;
        }

        public void OnGet()
        {
            String hostName = Dns.GetHostName();
            Console.WriteLine(hostName);
            ViewData["host"] = hostName;
            

        }
    }
}</pre>
<p>now if we run the application using IIS express we will have this view  :<br />
<a href="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2022/11/hostname.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1475" src="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2022/11/hostname.png" alt="" width="1708" height="888" srcset="/wp-content/uploads/2022/11/hostname.png 1708w, /wp-content/uploads/2022/11/hostname-300x156.png 300w, /wp-content/uploads/2022/11/hostname-1024x532.png 1024w, /wp-content/uploads/2022/11/hostname-768x399.png 768w, /wp-content/uploads/2022/11/hostname-1536x799.png 1536w, /wp-content/uploads/2022/11/hostname-750x390.png 750w, /wp-content/uploads/2022/11/hostname-1140x593.png 1140w" sizes="(max-width: 1708px) 100vw, 1708px" /></a>As you can see the goal here is to show the hostname , nothing special .</p>
<p>now we will dockeriz application by creating a dockerfile  with this content (full source code of the solution will be shared )</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">FROM mcr.microsoft.com/dotnet/aspnet:6.0-alpine AS base

WORKDIR /app
ENV ASPNETCORE_URLS http://+:5000
# EXPOSE 80
EXPOSE 5000

FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
WORKDIR /src
COPY ["hostnameapp/hostnameapp.csproj", "hostnameapp/"]
RUN dotnet restore "hostnameapp/hostnameapp.csproj"
COPY . .
WORKDIR "/src/hostnameapp"
RUN dotnet build "hostnameapp.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "hostnameapp.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "hostnameapp.dll"]</pre>
<p>now we will create the nginx application but we have some config for the app :<br />
we will create  a file : nginx.conf</p>
<pre class="EnlighterJSRAW" data-enlighter-language="nginx">worker_processes 4;
 
events { worker_connections 1024; }
 
http {
    sendfile on;
    limit_req_zone $binary_remote_addr zone=one:10m rate=5r/s;
    # upstream app_servers {
    #     #server app:127.0.0.1:5000;
    #   # server  http://backend:5000;
    # }
 
    server {
        listen 80;
 
        location / {
            proxy_pass          http://backend:5000;
            proxy_redirect     off;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host $server_name;
        }
    }
}</pre>
<p>Also we are going to docke the nginx proxy app</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">FROM nginx:alpine
RUN rm -r  /etc/nginx/nginx.conf
COPY nginx.conf /etc/nginx/nginx.conf</pre>
<p>now we can build both apps and run them to see what will happen .</p>
<p>let&#8217;s start with our dotnet application we need to build and run our solution :</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">docker build -t backend  .
docker run -it --rm -p 5000:5000   --name backend backend</pre>
<p>Now if you go to your browser and visit :  http://localhost:5000/ you will have this result :</p>
<p><a href="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2022/11/dockerps.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1477" src="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2022/11/dockerps.png" alt="" width="1542" height="805" srcset="/wp-content/uploads/2022/11/dockerps.png 1542w, /wp-content/uploads/2022/11/dockerps-300x157.png 300w, /wp-content/uploads/2022/11/dockerps-1024x535.png 1024w, /wp-content/uploads/2022/11/dockerps-768x401.png 768w, /wp-content/uploads/2022/11/dockerps-1536x802.png 1536w, /wp-content/uploads/2022/11/dockerps-750x392.png 750w, /wp-content/uploads/2022/11/dockerps-1140x595.png 1140w" sizes="(max-width: 1542px) 100vw, 1542px" /></a></p>
<p>And now as you can see our hostname have the id of the container .</p>
<p>now it&#8217;s time to run the nginx proxy that will be the entry to our application or let&#8217;s say the way we will expose our application .</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">docker build -t frontend  .
docker run -it --rm -p 8082:80   --name frontend frontend</pre>
<p>if we run those commandes the project will build but will not run and we will finish by having an error saying that host not found , the host is the backend that we defined in the config file with port 5000 , and that&#8217;s because the two containers are not in the same network !<br />
now let&#8217;s make some changes :<br />
Let&#8217;s create a network :</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">docker network create demonetwork-001;
#to inspect that network 
docker network inspect demonetwork-001;</pre>
<p>now we need to attach our containers to the network that we have created  :</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">docker network connect demonetwork-001 backend;
#this will fail because the container did exit beceause of error
docker network connect demonetwork-001 frontend;

--------------instead we will use this -------------------------
docker run -it --rm -p 5000:5000 --network=demonetwork-001  --name backend backend
docker run -it --rm -p 8082:80  --network=demonetwork-001  --name frontend frontend</pre>
<p>and like that we will have our result  while visiting our entry point on port 8082 :<a href="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2022/11/finalwithoutcompose.png"><br />
<img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1478" src="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2022/11/finalwithoutcompose.png" alt="" width="1902" height="884" srcset="/wp-content/uploads/2022/11/finalwithoutcompose.png 1902w, /wp-content/uploads/2022/11/finalwithoutcompose-300x139.png 300w, /wp-content/uploads/2022/11/finalwithoutcompose-1024x476.png 1024w, /wp-content/uploads/2022/11/finalwithoutcompose-768x357.png 768w, /wp-content/uploads/2022/11/finalwithoutcompose-1536x714.png 1536w, /wp-content/uploads/2022/11/finalwithoutcompose-750x349.png 750w, /wp-content/uploads/2022/11/finalwithoutcompose-1140x530.png 1140w" sizes="(max-width: 1902px) 100vw, 1902px" /></a></p>
<h2>Part 2- With Docker Compose</h2>
<p>now all we need is to create a docker compose file without editing our solutions : docker-compose.yml</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">version: "3.9"
services:
  app:
    build: ./hostnameapp
    expose: 
      - "5000"    
  proxy:
    #image: nginx:alpine
    build: ./nginx
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
    depends_on:
      - app
    links:
      - app  
    ports:
      - "8082:80"</pre>
<p>now in our file we define the two apps and we say that the proxy app depends on the first app let see the result :<br />
<a href="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2022/11/composefinal.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1480" src="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2022/11/composefinal.png" alt="" width="1808" height="827" srcset="/wp-content/uploads/2022/11/composefinal.png 1808w, /wp-content/uploads/2022/11/composefinal-300x137.png 300w, /wp-content/uploads/2022/11/composefinal-1024x468.png 1024w, /wp-content/uploads/2022/11/composefinal-768x351.png 768w, /wp-content/uploads/2022/11/composefinal-1536x703.png 1536w, /wp-content/uploads/2022/11/composefinal-750x343.png 750w, /wp-content/uploads/2022/11/composefinal-1140x521.png 1140w" sizes="(max-width: 1808px) 100vw, 1808px" /></a>and this is our goal , we want the backend not to be exposed to public and we want our frontend exposed as you can see on port 8082 and we can not acces the backend , now if we modify the config file and add different backends with different port the load balancer will play it&#8217;s role to manage the traffic between the apps .</p>
<p>Now if we have the same app on different port and we edit the config file like this ofr example :</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">worker_processes 4;
 
events { worker_connections 1024; }
 
http {
    sendfile on;
 
    upstream app_servers {
        server app:5000 weight=4;
        server app2:5010 weight=2;
    }
 
    server {
        listen 80;
 
        location / {
            proxy_pass         http://app_servers;
            proxy_redirect     off;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host $server_name;
        }
    }
}

</pre>
<p>the result will show that we balance between the two apps</p>
<p><a href="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2022/11/chrome-capture-2022-10-16.gif"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1481" src="https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/wp-content/uploads/2022/11/chrome-capture-2022-10-16.gif" alt="" width="1000" height="500" /></a></p>
<p>that&#8217;s it for this demo , in next post we will discuss how we will do this on <em>Azure Kubernetes Service</em> (<em>AKS</em>) .</p>
<p>&nbsp;</p>
<p>source code :<strong> <a href="https://bit.ly/3EDJVus">https://bit.ly/3EDJVus</a></strong></p>
]]></content:encoded>
					
					<wfw:commentRss>https://achrafbenalaya.com/2022/11/16/how-to-setup-nginx-reverse-proxy-for-aspnet-core-apps-with-and-without-docker-compose/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1471</post-id>	</item>
		<item>
		<title>Deploy azure function from Docker Hub CI/CD</title>
		<link>https://achrafbenalaya.com/2020/04/27/deploy-azure-function-from-docker-hub-ci-cd/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=deploy-azure-function-from-docker-hub-ci-cd</link>
					<comments>https://achrafbenalaya.com/2020/04/27/deploy-azure-function-from-docker-hub-ci-cd/#respond</comments>
		
		<dc:creator><![CDATA[achraf]]></dc:creator>
		<pubDate>Mon, 27 Apr 2020 22:30:09 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[docker]]></category>
		<guid isPermaLink="false">https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/?p=487</guid>

					<description><![CDATA[In the last blog post we have seen how to deploy azure function from visual studio 2019 . In this tutorial we are going to see how to deploy a function using docker hub . To use the commands used in powershell first you need to Install the Azure Functions Core Tools . The script used in the video [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In the last blog <a href="https://achrafbenalaya.github.io/Achrafbenalayablog/post/deploy_an_azure_function_created_from_visual_studio/">post</a> we have seen how to deploy azure function from visual studio 2019 .</p>
<p>In this tutorial we are going to see how to deploy a function using docker hub .</p>
<p><iframe title="Create and deploy Containerized Azure Functions  from docker hub CI/CD" width="500" height="281" src="https://www.youtube.com/embed/iNAn7L60cAY?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></p>
<p>To use the commands used in powershell first you need to Install the Azure Functions Core <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local#install-the-azure-functions-core-tools">Tools</a> .</p>
<p>The script used in the video :</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">func init –docker

func new

code .

docker build –tag account/fucnction:v1.

docker run -p 8080:80 -it account/fucnction:v1

docker push account/fucnction:v1</pre>
<p>&nbsp;</p>
<p>Happy DevOps day =)</p>
]]></content:encoded>
					
					<wfw:commentRss>https://achrafbenalaya.com/2020/04/27/deploy-azure-function-from-docker-hub-ci-cd/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">487</post-id>	</item>
		<item>
		<title>Installing WordPress with docker image of XAMPP</title>
		<link>https://achrafbenalaya.com/2020/04/21/installing-wordpress-with-docker-image-of-xampp/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=installing-wordpress-with-docker-image-of-xampp</link>
					<comments>https://achrafbenalaya.com/2020/04/21/installing-wordpress-with-docker-image-of-xampp/#respond</comments>
		
		<dc:creator><![CDATA[achraf]]></dc:creator>
		<pubDate>Tue, 21 Apr 2020 19:42:10 +0000</pubDate>
				<category><![CDATA[docker]]></category>
		<guid isPermaLink="false">https://achrafbenalaya-ekgvbjdjgta4b4hz.francecentral-01.azurewebsites.net/?p=406</guid>

					<description><![CDATA[Hi everyone ! , Today , in this new article we are going to see how to install wordpress on local machine, using xampp server from a docker image . First step we are going to pull an image of xampp from docker hub , for that I have found this docker image , You [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Hi everyone ! ,</p>
<p>Today , in this new article we are going to see how to install wordpress on local machine, using xampp server from a docker image .</p>
<p>First step we are going to pull an image of xampp from docker hub , for that I have found this docker image , You can download it using this command from your power shell or your favorite command tool :</p>
<p>https://hub.docker.com/r/tomsik68/xampp/</p>
<p>while your pulling this image from docker hub , you can in same time , download word press from the official website the version that exist right now , while i’m writing this article is version : 5.2.2 .</p>
<p>After all is done , now let’s see our image and run it .</p>
<p>To see our image we simply type : docker images and if you have been using docker for a while , you will have a couple of images like I do in picture below .</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone size-medium" src="https://achrafbenalaya.github.io/Achrafbenalayablog/img/post3/img11.png" width="1024" height="216" /></p>
<p><strong>docker</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">docker run –name myXampp -p 41061:22 -p 41062:80 -d -v C:\Users\Heero\Downloads\Compressed\wordpress-5.2.2\wordpress:/www tomsik68/xampp</pre>
<p>&nbsp;</p>
<p>Now let’s understand this command .</p>
<p>The command above will expose the SSH server on port 41061 and HTTP server on port 41062.</p>
<p>one thing you should do is , to replace the directory where you have downloaded wordpress, for me</p>
<p>C:\Users\Heero\Downloads\Compressed\wordpress-5.2.2\wordpress , so in the command you should :</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">docker run –name myXampp -p 41061:22 -p 41062:80 -d -v Your directory :/www tomsik68/xampp</pre>
<p>After you run the command , by typing : docker ps you will see your working container :</p>
<p><img loading="lazy" decoding="async" class="alignnone size-medium" src="https://achrafbenalaya.github.io/Achrafbenalayablog/img/post3/img12.png" width="1024" height="90" /></p>
<p>To connect to your web page, visit this URL: <em>http://localhost:41062/www </em></p>
<p>And to open up the XAMPP interface:  <em>http://localhost:41062/</em></p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone size-medium" src="https://achrafbenalaya.github.io/Achrafbenalayablog/img/post3/img13.png" width="855" height="716" /></p>
<p><img loading="lazy" decoding="async" class="alignnone size-medium" src="https://achrafbenalaya.github.io/Achrafbenalayablog/img/post3/img1.4.png" width="940" height="498" /></p>
<p><img loading="lazy" decoding="async" class="alignnone size-medium" src="https://achrafbenalaya.github.io/Achrafbenalayablog/img/post3/img1.6.png" width="1002" height="633" /></p>
<p><img loading="lazy" decoding="async" class="alignnone size-medium" src="https://achrafbenalaya.github.io/Achrafbenalayablog/img/post3/img1.7.png" width="1024" height="525" /></p>
<p>Now one more free tip , if you try to install a plugin you will get an error .</p>
<p>WordPress will be asking for FTP credentials on localhost and for that , there is a fix in 2 steps .</p>
<p><strong>config.php</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">define(‘FS_METHOD’,‘direct’);

</pre>
<p><strong>Directory</strong></p>
<p>now we need to change the permission in our installation folder to “Read &amp; Write” for everyone :</p>
<p><img loading="lazy" decoding="async" class="alignnone size-medium" src="https://achrafbenalaya.github.io/Achrafbenalayablog/img/post3/img1.8.png" width="713" height="452" /></p>
<p>Now , you are ready to go and to use your WordPress site and start publishing your articles !</p>
<p>Happy WordPress day <img src="https://s.w.org/images/core/emoji/15.0.3/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://achrafbenalaya.com/2020/04/21/installing-wordpress-with-docker-image-of-xampp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">406</post-id>	</item>
	</channel>
</rss>
