<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sumana Basu</title>
    <description>The latest articles on DEV Community by Sumana Basu (@sumana2001).</description>
    <link>https://dev.to/sumana2001</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F505078%2F400c04b8-0205-438b-be8c-a046fd904ca6.jpg</url>
      <title>DEV Community: Sumana Basu</title>
      <link>https://dev.to/sumana2001</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sumana2001"/>
    <language>en</language>
    <item>
      <title>Build a custom MySQL Docker Container</title>
      <dc:creator>Sumana Basu</dc:creator>
      <pubDate>Sun, 08 Jan 2023 06:01:50 +0000</pubDate>
      <link>https://dev.to/sumana2001/build-a-custom-mysql-docker-container-404f</link>
      <guid>https://dev.to/sumana2001/build-a-custom-mysql-docker-container-404f</guid>
      <description>&lt;p&gt;Tired of going through endless documentation for setting up your database in any computer apart from your local computer? Setting up a database every time you want to do some API testing? Well, Docker is here to help you out and spin up a local database. This will make it super easy for you to test their code and write data without installing and configuring a lot of tools. In the beginning stages of development, of course, you wouldn't want to spend hours configuring the database so a custom MySQL container can change your life!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is docker❓
&lt;/h2&gt;

&lt;p&gt;Docker is an application build and deployment tool to help you create, run and deploy applications. It uses the concept of container i.e. you create a package of your code with dependencies that can be deployed as one single unit. Although the concept of containers has been around for a long time, docker makes the tasks of setting up and handling the containers very easy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's start creating! 🔥
&lt;/h2&gt;

&lt;p&gt;We will be creating and deploying a custom docker image. What can this docker image do? It can:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a database "marvel"&lt;/li&gt;
&lt;li&gt;Create a table "superheroes"&lt;/li&gt;
&lt;li&gt;Set the superhero_id to auto_increment&lt;/li&gt;
&lt;li&gt;Insert 10 records into the table&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Before starting make sure you have Docker installed. If not, you can install it from &lt;a href="https://docs.docker.com/desktop/" rel="noopener noreferrer"&gt;here&lt;/a&gt;. Create a project folder let's call it &lt;code&gt;marvel_db&lt;/code&gt;. Here's what the project structure would look like. We'll go through each of the files one by one.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ni8g5ur8ob94ait7a2a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ni8g5ur8ob94ait7a2a.png" alt="Project Structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create the SQL scripts 📜
&lt;/h2&gt;

&lt;p&gt;Create a folder called &lt;code&gt;scripts&lt;/code&gt; to store both your SQL files, one for creating the database and table and the second one for inserting the new records. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Pro tip:&lt;/strong&gt; Be careful with what you name these files because docker will go through them in alphabetical order. So if the name of the file inserting the records is alphabetically before the file creating the table, you might face a lot of errors.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's name our first file &lt;code&gt;create_table.sql&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;

&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="n"&gt;IF&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;EXISTS&lt;/span&gt; &lt;span class="nv"&gt;`marvel`&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="nb"&gt;CHARACTER&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;utf8&lt;/span&gt; &lt;span class="k"&gt;COLLATE&lt;/span&gt; &lt;span class="n"&gt;utf8_general_ci&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;GO&lt;/span&gt;
&lt;span class="n"&gt;USE&lt;/span&gt; &lt;span class="nv"&gt;`marvel`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;GO&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="nv"&gt;`superheroes`&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nv"&gt;`superhero_id`&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nv"&gt;`name`&lt;/span&gt; &lt;span class="nb"&gt;varchar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nv"&gt;`color`&lt;/span&gt; &lt;span class="nb"&gt;varchar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nv"&gt;`noOfMovies`&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;ENGINE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;InnoDB&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="n"&gt;CHARSET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;utf8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;GO&lt;/span&gt;
&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="nv"&gt;`superheroes`&lt;/span&gt;
  &lt;span class="k"&gt;ADD&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;`superhero_id`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;GO&lt;/span&gt;
&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="nv"&gt;`superheroes`&lt;/span&gt;
  &lt;span class="k"&gt;MODIFY&lt;/span&gt; &lt;span class="nv"&gt;`superhero_id`&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="n"&gt;AUTO_INCREMENT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;So here's what we have done in the above code. We create a database &lt;code&gt;marvel&lt;/code&gt; if it already doesn't exist. Then we go inside that database and create a new table &lt;code&gt;superheroes&lt;/code&gt;. Next, we set &lt;code&gt;superhero_id&lt;/code&gt; as the primary key of the table and set it to &lt;code&gt;auto_increment&lt;/code&gt;. The &lt;code&gt;GO&lt;/code&gt; command used after every query is a batch separator in SQL that tells SQL that there are more statements to be executed in the SQL file.&lt;/p&gt;

&lt;p&gt;Now we'll create the second file, let's call it &lt;code&gt;insert_table.sql&lt;/code&gt; for inserting 10 new records.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;

&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="nv"&gt;`superheroes`&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;`name`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nv"&gt;`color`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nv"&gt;`noOfMovies`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;VALUES&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;"Iron Man"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;"Gold"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;"Captain America"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nv"&gt;"Blue"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;"Thor"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nv"&gt;"Dark Grey"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;"Hulk"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nv"&gt;"Green"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;"Black Widow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nv"&gt;"Red"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;"Hawkeye"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nv"&gt;"Grey"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;"Wanda Maximoff"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nv"&gt;"Dark Red"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;"Black Panther"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nv"&gt;"Purple"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;"War Machine"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nv"&gt;"Black"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;"Spider Man"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;"Blue"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Create Dockerfile 🐳
&lt;/h2&gt;

&lt;p&gt;Now that our sample database is complete, we will create a &lt;code&gt;Dockerfile&lt;/code&gt; to actually run these scripts.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;

&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; mysql:latest &lt;/span&gt;
&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; MYSQL_DATABASE marvel&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; ./scripts/ /docker-entrypoint-initdb.d/&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Confused about the above code? Here's what it means. In this tutorial, we're creating a custom MySQL image which means we are taking MySQL's own docker image as a starting point for ours. So the first line is calling the latest version of the MySQL docker image. Next, the second line means that we are creating a MySQL database called &lt;code&gt;marvel&lt;/code&gt; as soon as the Dockerfile is run. Lastly, the third line copies all the scripts in the script folder to docker-entrypoint-initdb.d/ which will be automatically executed during container setup.&lt;/p&gt;

&lt;h2&gt;
  
  
  See it in action 🎬
&lt;/h2&gt;

&lt;p&gt;Guess what? We have created our custom MySQL Docker container. Let's build it and check if it works.&lt;br&gt;
Run the command in your terminal to build the docker image with the name marveldb.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

docker build -t marveldb:1.0 .


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhvgrz4dfdwbtx69a0p1r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhvgrz4dfdwbtx69a0p1r.png" alt="Build command"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Pro tip:&lt;/strong&gt; Docker images built with an ARM64 based architecture like the Apple Silicon chip can create issues when deploying images to a Linux or Windows-based AMD64 environment like AWS EC2, ECS, etc. So, you need a way to build AMD64 based images on the ARM64 architecture which you can build by using the flag &lt;code&gt;--platform linux/x86_64&lt;/code&gt; as used above. Windows and Linux users don't need to use this flag.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can check if your new image is running with the command &lt;code&gt;docker images&lt;/code&gt;. Now run the docker container with the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

docker run -d -p 3306:3306 --name marvelDB \
-e MYSQL_ROOT_PASSWORD=12Marvel --platform linux/x86_64 marveldb:1.0


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Again you can leave out the platform flag if you are using Windows or Linux. You check if your container is running with the command &lt;code&gt;docker container ls&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Execute the container to run SQL queries:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

docker exec -it marvelDB bash 


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Go inside the MySQL terminal:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

mysql -uroot -p


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You'll be prompted to enter the password. Write the root password you used while running the container, in our case &lt;code&gt;12Marvel&lt;/code&gt;. Now you can run whatever SQL queries you want you will notice, you have the marvel database and superheroes table already created with 10 records in it. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fstu57gqo3rf3an5cdkcw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fstu57gqo3rf3an5cdkcw.png" alt="MySQL Output 1"&gt;&lt;/a&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fak1sq20so6l3gbqnpymx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fak1sq20so6l3gbqnpymx.png" alt="MySQL Output 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Take it one step further 🪜
&lt;/h2&gt;

&lt;p&gt;In industries or big organizations, there is usually not just one docker container. They have many services or containers that they have to manage together. So instead of running and building each container, we can use a docker-compose file. It stores all the essential information about all the services and now you can run countless containers with one single command. Let's start by creating a &lt;code&gt;docker-compose.yml&lt;/code&gt; file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;

&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;3.7"&lt;/span&gt;
&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;marvelDB&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;marveldb:1.0"&lt;/span&gt;
        &lt;span class="na"&gt;platform&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;linux/x86_64&lt;/span&gt;
        &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;MYSQL_ROOT_PASSWORD&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;12Marvel"&lt;/span&gt;
        &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;3306:3306"&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;That's it! Run the docker compose:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

docker-compose up   


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;It will create a service called marvel_db(name of our project folder) inside which there is a container with the name &lt;code&gt;marvel_db_marvelDB_1&lt;/code&gt;. You can confirm the name of your container using &lt;code&gt;docker container ls&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now you can again run the &lt;code&gt;exec&lt;/code&gt; command and get the exact same result. This process might not seem that fruitful in this example, but when things get more complex, the docker compose file makes a huge difference.&lt;/p&gt;

&lt;h2&gt;
  
  
  Push to docker hub ☁️
&lt;/h2&gt;

&lt;p&gt;Wow! We're in the endgame now! The last thing to do is to push your custom MySQL container to the cloud so that anyone from anywhere can access it. &lt;/p&gt;

&lt;p&gt;First, create an account on &lt;a href="https://hub.docker.com/" rel="noopener noreferrer"&gt;Docker Hub&lt;/a&gt;. Create a repository and give it a name and description. Then, from the terminal, run &lt;code&gt;docker login&lt;/code&gt; and enter your credentials.&lt;/p&gt;

&lt;p&gt;Now, tag your image:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

docker tag local-image:tagname username/new-repo:tagname


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In my case:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

docker tag marveldb:1.0 sumana2001/marvel:1.0


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next, push your image to the new repository&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

docker push username/new-repo:tagname


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In my case:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

docker push sumana2001/marvel:1.0


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;When the process is complete, you will be able to pull your image from anywhere using the command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

docker pull username/new-repo:tagname


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In my case:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&lt;p&gt;docker pull sumana2001/marvel&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Outro 💚&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;We have successfully created a custom MySQL container. From here, the sky is the limit. We can add endless functionalities on top of different prebuilt images and that's the beauty of docker. If you got stuck anywhere you can check out the entire source code on &lt;a href="https://github.com/sumana2001/marvel_db" rel="noopener noreferrer"&gt;Github&lt;/a&gt; and view the live repository on &lt;a href="https://hub.docker.com/r/sumana2001/marvel" rel="noopener noreferrer"&gt;Docker Hub&lt;/a&gt;.&lt;br&gt;
In case you have some questions regarding the article or want to discuss something under the sun feel free to connect with me on &lt;a href="https://www.linkedin.com/in/sumana-basu/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; 💕&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you run an organisation and want me to write for you please do connect with me 🙈&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>docker</category>
      <category>mysql</category>
    </item>
    <item>
      <title>Make your first Chrome Extension | Ad Blocker</title>
      <dc:creator>Sumana Basu</dc:creator>
      <pubDate>Thu, 24 Feb 2022 07:35:45 +0000</pubDate>
      <link>https://dev.to/sumana2001/make-your-first-chrome-extension-ad-blocker-426f</link>
      <guid>https://dev.to/sumana2001/make-your-first-chrome-extension-ad-blocker-426f</guid>
      <description>&lt;p&gt;&lt;strong&gt;Google Chrome extensions&lt;/strong&gt; are programs that can be installed into Chrome in order to change the browser's functionality. There are many amazing extensions on the web-store but personally, my favourite one is ad-blocker.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo1ype7brlqave3ipw2hw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo1ype7brlqave3ipw2hw.png" alt="Chrome"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is an ad blocker?
&lt;/h2&gt;

&lt;p&gt;An &lt;strong&gt;ad blocker&lt;/strong&gt; is a piece of software that blocks network requests to and/or from advertising servers. Well, that's a bookish definition. Let's understand it in a better way.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjt8s84d50775qosehjiq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjt8s84d50775qosehjiq.png" alt="Ad blocker"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So let's say, I want to watch a YouTube video. When I click on the video my browser i.e. Google Chrome sends a request to YouTube asking it to send that particular video. Then YouTube tells the browser that I am sending the video but before that please send some requests to my advertisers as well. This way you get back the ads and the video.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flq9b0gy0j0j0429cdy22.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flq9b0gy0j0j0429cdy22.png" alt="Ad Blocker Concept"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, what do ad blockers do? It blocks any requests to these advertisement servers. It runs alongside the browser and checks the network traffic to prevent the browser from sending the requests to advertisers.&lt;/p&gt;
&lt;h2&gt;
  
  
  Let's jump into the code
&lt;/h2&gt;

&lt;p&gt;Firstly let's make the project structure as given below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fywhudrinaqcpxhh0yyiv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fywhudrinaqcpxhh0yyiv.png" alt="Project Structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we'll create our manifest.json file which will contain all the important information about the extension like name, version etc.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "Aliferous Adblocker",
  "version": "1.0",
  "description": "Adblocker chrome extension",
  "permissions": [
    "webRequest",
    "webRequestBlocking",
    "&amp;lt;all_urls&amp;gt;"
  ],
  "background": {
    "scripts": [
      "background.js"
    ]
  },
  "icons": {
    "16": "icons/logo_16.png",
    "48": "icons/logo_48.png",
    "128": "icons/logo_128.png"
  },
  "manifest_version": 2
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The icons mentioned above are the same image of different sizes i.e. 16X16, 48X48, 128X128. This is the logo of the ad blocker. You can choose any image and then change its sizes here. Add all the three logos in the icons folder named logo_16.png, logo_48.png and so on.&lt;/p&gt;

&lt;p&gt;Now let's create the background.js file. In this file we'll call the chrome API and add event listeners. We'll add an event listener just before sending the request so that it can check the request and block it if needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const filters = [
    "*://*.doubleclick.net/*",
    "*://partner.googleadservices.com/*",
    "*://*.googlesyndication.com/*",
    "*://*.google-analytics.com/*",
    "*://creative.ak.fbcdn.net/*",
    "*://*.adbrite.com/*",
    "*://*.exponential.com/*",
    "*://*.quantserve.com/*",
    "*://*.scorecardresearch.com/*",
    "*://*.zedo.com/*",
]

chrome.webRequest.onBeforeRequest.addListener(
    function(details) {return {cancel:true}},
    { urls: filters},
    ["blocking"]
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the constant "filters", you can add the servers from where your ads are coming. And that's it! You're done!🥳&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's run your own ad blocker!
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Go to chrome://extensions/&lt;/li&gt;
&lt;li&gt;Switch on developers mode&lt;/li&gt;
&lt;li&gt;Click on load unpacked and select the folder in which you made the ad blocker&lt;/li&gt;
&lt;li&gt;Now try going to any of the websites given in the filters and you'll see that it's blocked.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz9vskuxwlf79r4q4frms.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz9vskuxwlf79r4q4frms.png" alt="Ad Blocked"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you see an output like this, it means you successfully made your first chrome extension!!🎉&lt;/p&gt;

&lt;p&gt;You can get the whole source code here👇&lt;br&gt;
&lt;a href="https://github.com/sumana2001/Ad-Blocker" rel="noopener noreferrer"&gt;https://github.com/sumana2001/Ad-Blocker&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
