<?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; CodePills.com</title>
	<atom:link href="https://codepills.com/tag/docker/feed/" rel="self" type="application/rss+xml" />
	<link>https://codepills.com</link>
	<description>Helping you make a better code</description>
	<lastBuildDate>Sun, 19 Jun 2022 17:12:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Create PostgreSQL database for integration testing with Docker</title>
		<link>https://codepills.com/create-postgresql-database-for-integration-testing-with-docker/</link>
					<comments>https://codepills.com/create-postgresql-database-for-integration-testing-with-docker/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Mon, 01 Nov 2021 17:33:29 +0000</pubDate>
				<category><![CDATA[Solutions]]></category>
		<category><![CDATA[CI/CD]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[Dockerfile]]></category>
		<category><![CDATA[integration tests]]></category>
		<category><![CDATA[IntelliJ]]></category>
		<category><![CDATA[postgresql]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1264</guid>

					<description><![CDATA[In this article, we will explore the idea of creating a PostgreSQL database Dockerfile. We can, for example, use it for creating integration tests in a separate CI/CD workflow. <a href="https://codepills.com/create-postgresql-database-for-integration-testing-with-docker/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>In this article, we will explore the idea of creating a PostgreSQL database Dockerfile. We can, for example, use it for creating integration tests in a separate CI/CD workflow.</p>
<p><span id="more-1264"></span></p>
<h2>Introduction</h2>
<p>Let&#8217;s have an idea to create a separate database for integration testing. Creating a separate database will require creating a Docker file with a PostgreSQL database. We can consequently make and run dedicated integration CI/CD workflow for the integration tests. This CI/CD workflow will take our Docker PostgreSQL database and run the database with which integration tests will be working.</p>
<h2>Creating Dockerfile</h2>
<p>We will need to write three files for creating a database testing environment. Technically, we need to write only one file &#8211; <code>Dockerfile</code>. But two other files, database init scripts, will be used to prepare our containerized database for integration tests.</p>
<p>First we need to write PostgreSQL <code>Dockerfile</code>:</p>
<pre><code class="language-yaml">FROM postgres:latest
ENV POSTGRES_USER postgres
ENV POSTGRES_PASSWORD admin
ENV POSTGRES_DB postgres
COPY ./sql/db_user_creation.sql /docker-entrypoint-initdb.d/
COPY ./sql/init_tables.sql /docker-entrypoint-initdb.d/</code></pre>
<p>Let&#8217;s take latest image of PostgreSQL database from posgres Docker vendor. We set up PostgreSQL&#8217;s image environment properties <code>POSTGRES_USER</code>, <code>POSTGRES_PASSWORD</code> and <code>POSTGRES_DB</code> by default values and copy our database init scripts to Docker image entry folder.</p>
<p>The official postgres docker image will run <code>.sql</code> scripts found in the <i>/docker-entrypoint-initdb.d/</i> folder. I highly encourage you to check <a href="https://hub.docker.com/_/postgres" title="Docker Hub Postgres official page" target="_blank" rel="nofollow noopener">official documentation</a> in case in future postgres releases might change this.</p>
<h3>Best practice</h3>
<p>I will go here a little bit sideways. There is a good practice to add on custom-defined <code>Dockerfile</code> last Docker commands from a source image.</p>
<pre><code class="language-yaml">ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 5432
CMD ["postgres"]</code></pre>
<p>The last three lines of our <code>Dockerfile</code> are copied from the Postgres image and considered a best practice. However, you can omit them. But in case you want to extend this <code>Dockerfile</code> further, please realize that first, you are running all commands in the Postgres source image. And only then you are running your custom Docker commands. Placing the last command from PostgreSQL&#8217;s image will secure consistent API.</p>
<p>Therefore, the Whole <code>Dockerfile</code> should look like this:</p>
<pre><code class="language-yaml">FROM postgres:latest
ENV POSTGRES_USER postgres
ENV POSTGRES_PASSWORD admin
ENV POSTGRES_DB postgres
COPY ./sql/db_user_creation.sql /docker-entrypoint-initdb.d/
COPY ./sql/init_tables.sql /docker-entrypoint-initdb.d/
ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 5432
CMD ["postgres"]</code></pre>
<p>The environment variables will instruct the container to create a <i>postgres</i> schema with <i>postgres</i> user (having <i>admin</i> password) on its first run. Any <code>.sql</code> files found in the <i>/docker-entrypoint-initdb.d/</i> of the PostgreSQL container will be executed. If you want to execute <code>.sh</code> scripts, you can also place them in the <i>/docker-entrypoint-initdb.d/</i> folder.</p>
<h2>Custom init scripts</h2>
<p>As you have noticed in <code>Dockerfile</code> description, we have created two other files which we copied to PostgreSQL image. First file is <code>db_user_creation.sql</code>:</p>
<pre><code class="language-sql">CREATE USER mycustomsuperadmin WITH PASSWORD 'changethispassword';
GRANT ALL PRIVILEGES ON DATABASE postgres TO mycustomsuperadmin;</code></pre>
<p>In this file, we could, for example, add a command for creating another database. However, only for demonstration purpose, we will create <i>mycustomsuperadmin</i> user with all the privileges for <i>postgres</i> database. Creating a new user is not mandatory.</p>
<p>The second file we need to create is the initialization of our database with tables and content. This file is also just for demonstration purposes, and you can come with your ideas and needs for what you need to put into the database. Here is example of some database tables we will pad into <i>postgres</i> database.</p>
<pre><code class="language-sql">CREATE TABLE "public".items (
    "id"           integer NOT NULL GENERATED ALWAYS AS IDENTITY (start 1),
    name           varchar(50) NOT NULL,
    price          double precision NOT NULL,
    release        timestamptz(3) NOT NULL,
    CONSTRAINT     PK_Customer PRIMARY KEY ("id", "name", "price", "release")
);

CREATE TABLE "public".users (
    "id"           integer NOT NULL GENERATED ALWAYS AS IDENTITY (start 1),
    name           varchar(50) NOT NULL,
    salary         double precision
    timestamp      timestamptz(3) NOT NULL,
    CONSTRAINT     PK_Customer PRIMARY KEY ("id", "name", "salary", "timestamp")
);</code></pre>
<p>Again, the following code is just for demonstration purposes, and naturally, you can place your own init scripts here.</p>
<p><b>Note</b> : Default syntax for creating database in PostgreSQL is &#8220;database_name&#8221;.&#8221;scheme_name&#8221;.&#8221;table_name&#8221;.</p>
<h2>Build Dockerfile</h2>
<p>Now, when we have all the files, we need to run the Docker build command. So, go to the folder where you placed PostgreSQL <code>Dockerfile</code> and run Docker build command like this:</p>
<h3>IntelliJ configuration</h3>
<p>You can easily build and run your Docker image from IntelliJ. Check the image of configuration for setting up the file:</p>
<p><img fetchpriority="high" decoding="async" src="https://codepills.com/wp-content/uploads/2021/11/intellij_postgresql_docker_build_runner_settings.png" alt="IntelliJ PostgreSQL Docker build runner settings" width="635" height="522" class="alignnone size-full wp-image-1265" srcset="https://codepills.com/wp-content/uploads/2021/11/intellij_postgresql_docker_build_runner_settings.png 635w, https://codepills.com/wp-content/uploads/2021/11/intellij_postgresql_docker_build_runner_settings-300x247.png 300w" sizes="(max-width: 635px) 100vw, 635px" /></p>
<pre><code class="language-yaml">Docker build .</code></pre>
<p>Hitting the following setup in IntelliJ will build your <code>Dockerfile</code> and place it in your local Docker repository.</p>
<h2>Alternative with docker-compose</h2>
<p>There is alternative way how to build and run PostgreSQL locally. It is without creating Docker image and instead just run <code>docker-compose</code>. Here is a code for <code>docker-compose.yaml</code> file:</p>
<pre><code class="language-yml">version: '3.7'
services:
    postgres:
        image: postgres:latest
        restart: always
        environment:
            POSTGRES_USER: postgres
            POSTGRES_PASSWORD: admin
            POSTGRES_DB: postgres
        logging:
            options:
                max-size: 10m
                max-file: "3"
        ports:
            - '5432:5432'
        volumes:
            - ./postgres-data:/var/lib/postgresql/data
            # copy the sql script to create tables
            - .sql/init_tables.sql:/docker-entrypoint-initdb.d/init_tables.sql
            # copy the sql script to create user
            - .sql/db_user_creation.sql:/docker-entrypoint-initdb.d/db_user_creation.sql</code></pre>
<p>Running <code>docker-compose up -d</code> will run docker-compose script in your repository. To turn off the service, execute command <code>docker-compose down</code>.</p>
<p><b>Node</b>: So if you placed your Dockerfile in <i>project-root/src/test/resources</i> and you are in your command prompt on this sys-path, running docker-compose might first run docker-compose in your <i>project-root/</i> folder.</p>
<h2>Conclusion</h2>
<p>This article has shown us how to create a PostgreSQL database Dockerfile. However, we can develop this idea further and, for example, make it for integration tests in a separate CI/CD workflow.</p>
<p>Did you find creating <code>Dockerfile</code> easy? Do you have your trick or know another way <u>how to create Dockerfile</u>? Let us know in the comments below the article. We would like to hear your ideas and stories.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/create-postgresql-database-for-integration-testing-with-docker/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to use Docker for WordPress development</title>
		<link>https://codepills.com/how-to-use-docker-for-wordpress-development/</link>
					<comments>https://codepills.com/how-to-use-docker-for-wordpress-development/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Mon, 25 Nov 2019 14:12:49 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1036</guid>

					<description><![CDATA[This is a simple tutorial on how to start using Docker for WordPress development. <a href="https://codepills.com/how-to-use-docker-for-wordpress-development/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>This article is a simple tutorial on how to start using Docker for WordPress development.</p>
<p><span id="more-1036"></span></p>
<p>In the last couple of months, I had a problem with the XAMPP MySQL database. Without any particular reason, from one day to another, it just failed. XAMPP UI does not show any error.</p>
<p>DB recovery does not help, and it seems that every StackOverflow solution does not work. And digging deeper into the database stack did not bring any working solution.</p>
<p>The only solution which seems to work is to delete the XAMPP entirely and create a fresh new installation. Of course, this is a very tedious and time-consuming solution.</p>
<p>Moreover new MacOS update Catalina just made things worse, and XAMPP MySQL failed instantly. Instead of starting using MAMP, which is just the same way of doing things as XAMPP, I have decided it is the right time to start utilizing the power of Docker for WordPress development.</p>
<h2>Using Docker for WordPress development</h2>
<p>I have decided to create this simple tutorial for WordPress development with Docker for whoever would like to need it. This tutorial is written for macOS/Unix systems based operating systems. However, it is helpful for Windows users as well.</p>
<p>Here is a simple list of steps necessary for starting WordPress development with Docker:</p>
<h2>Step no. 1 &#8211; Install Docker</h2>
<p>Well, of course, the first step is to install Docker itself. I will step over this step while this could be a stand-alone tutorial for that. However, it is super easy, and it can complete even beginner PC user alone.</p>
<h2>Step no. 2 &#8211; Think what do you need for WordPress development</h2>
<p>We will need three containers for WordPress development with Docker. These containers will be:</p>
<ul>
<li>PHP server running WordPress</li>
<li>MySQL or MariaDB database based on your choice</li>
<li>Access to database (over phpMyAdmin GUI)</li>
</ul>
<p>Accessing the database over GUI is optional. Same as selecting the database of your choice. MySQL or MariaDB is up to your preference. So based on what are your needs, you should check the appropriate section in the next step.</p>
<h2>Step no. 2 &#8211; Create docker-compose.yml file</h2>
<p>Create a new directory for a project you want to develop. It will be the location of your choice. This folder should contain single file <code>docker-compose.yml</code>.</p>
<p><b>TIP:</b> There is a nice hack for doing all the steps in one. Just type in your terminal this command <code>mkdir NEW_PROJECT_NAME && cd $_ && touch docker-compose.yml</code> and you will all do this in one line.</p>
<p>Copy code below to <b>docker-compose.yml</b></p>
<pre><code class="language-yml">version: "3.1"

networks:
  wp:

volumes:
  db_storage:

services:

  wordpress:
    container_name: CUSTOM_PROJECT_NAME_wordpress
    image: wordpress
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    volumes:
        - ./:/var/www/html/wp-content
    ports:
      - 80:80
      - 443:443
    networks:
      - wp
    depends_on:
      - db

  db:
    container_name: CUSTOM_PROJECT_NAME_db
    image: mariadb
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    volumes:
      - db_storage:/var/lib/mysql
    ports:
      - 3306:3306
    networks:
      - wp

  phpmyadmin:
    container_name: CUSTOM_PROJECT_NAME_db_gui
    image: phpmyadmin
    restart: always
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: password
    ports:
      - 8080:80
    networks:
      - wp
    depends_on:
      - db</code></pre>
<p>Let&#8217;s cut down the composer file to pieces and figure out what it does.</p>
<pre><code class="language-yml">version: "3.1"

networks:
  wp:

volumes:
  db_storage:

services:</code></pre>
<table class="table">
<thead>
<tr>
<th scope="col">Line</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row">version: &#8220;3.1&#8221;</td>
<td>Version of the Compose file format. Version 3 or higher is the most current and recommended to use.</td>
</tr>
<tr>
<td scope="row">networks: wp:</td>
<td>All networks used for the service. We need to create just one custom network for our containers.</td>
</tr>
<tr>
<td scope="row">volumes: db_storage:</td>
<td>All volumes used for the service. We need to create just one custom volume for our containers.</td>
</tr>
<tr>
<td scope="row">services:</td>
<td>All containers used for this service. We need to create just one custom service.</td>
</tr>
</tbody>
</table>
<pre><code class="language-yml">wordpress:
    container_name: CUSTOM_PROJECT_NAME_wordpress
    image: wordpress
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - ./:/var/www/html/wp-content
    ports:
      - 80:80
      - 443:443
    networks:
      - wp
    depends_on:
      - db</code></pre>
<table class="table">
<thead>
<tr>
<th scope="col">Line</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row">container_name</td>
<td>Define the container name in CUSTOM_PROJECT_NAME_wordpress.</td>
</tr>
<tr>
<td scope="row">image: wordpress</td>
<td>If you do not define nothing, latest version of Docker file will be downloaded. To specify custom version of WordPress just add double dot e.g.: wordpress:5.3.0</td>
</tr>
<tr>
<td scope="row">restart: always</td>
<td>Define restart policy &#8211; <a href="//docs.docker.com/compose/compose-file/#restart”" rel="”nofollow” noopener" target="”_blank”">Docker reference</a></td>
</tr>
<tr>
<td scope="row">volumes:<br />
                &#8211; ./:/var/www/html/wp-content</td>
<td>Local folder mapped to container wp-content path. For normal theme or plugin development we do not need to access WordPress core file. <a href="//hub.docker.com/_/wordpress”" rel="”nofollow” noopener" target="”_blank”">Docker WordPress image</a></td>
</tr>
<tr>
<td scope="row">environment:<br />
                WORDPRESS_DB_HOST: db:3306<br />
                WORDPRESS_DB_USER: wordpress<br />
                WORDPRESS_DB_PASSWORD: wordpress<br />
                WORDPRESS_DB_NAME: wordpress</td>
<td>WordPress Docker environment. If you use containers just locally, I would suggest to keep this dummy passwords. Otherwise you are free to change it to your needs. <a href="https://docs.docker.com/compose/compose-file/#environment" target="_blank" rel="nofollow noopener">Docker environment</a></td>
</tr>
<tr>
<td scope="row">ports:<br />
                &#8211; 80:80<br />
                &#8211; 443:443</td>
<td>I/O ports for HTTP and HTTPS</td>
</tr>
<tr>
<td scope="row">networks:<br />
                &#8211; wp</td>
<td>Network to join.</td>
</tr>
<tr>
<td scope="row">depends_on:<br />
                &#8211; db</td>
<td>Dependency declaration.</td>
</tr>
</tbody>
</table>
<p><strong>With just a simple change of DB image from MariaDB to MySQL, you can get different database engine according to your needs. Otherwise, everything is the same for both containers.</strong></p>
<pre><code class="language-yml">db:
    container_name: CUSTOM_PROJECT_NAME_db
    image: mariadb
    # image: mysql
    restart: always
    environment:
        MYSQL_ROOT_PASSWORD: password
        MYSQL_DATABASE: wordpress
        MYSQL_USER: wordpress
        MYSQL_PASSWORD: wordpress
    volumes:
        - db_storage:/var/lib/mysql
    ports:
        - 3306:3306
    networks:
        - wp
</code></pre>
<table class="table">
<thead>
<tr>
<th scope="col">Line</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row">container_name</td>
<td>Define the container name in CUSTOM_PROJECT_NAME_wordpress.</td>
</tr>
<tr>
<td scope="row">image: mariadb</td>
<td>If you do not define nothing, latest version of Docker file will be downloaded. <a href="//hub.docker.com/_/mariadb/”" rel="”nofollow” noopener" target="”_blank”">Docker MariaDB image</a><br />If you want to MySQL database instead of MariaDB, type just <code><b>image: mysql</b></code> and latest image of MySQL will be downloaded.</td>
</tr>
<tr>
<td scope="row">restart: always</td>
<td>Define restart policy &#8211; <a href="//docs.docker.com/compose/compose-file/#restart”" rel="”nofollow” noopener" target="”_blank”">Docker reference</a></td>
</tr>
<tr>
<td scope="row">volumes:<br />
                &#8211; db_storage:/var/lib/mysql</td>
<td>Name volume allow data persistence without bothering where the data are stored.</td>
</tr>
<tr>
<td scope="row">environment:<br />
                MYSQL_ROOT_PASSWORD: password<br />
                MYSQL_DATABASE: wordpress<br />
                MYSQL_USER: wordpress<br />
                MYSQL_PASSWORD: wordpress</td>
<td>WordPress Docker environment. If you use containers just locally, I would suggest to keep this dummy passwords. Otherwise you are free to change it to your needs. <a href="https://docs.docker.com/compose/compose-file/#environment" target="_blank" rel="nofollow noopener">Docker environment</a></td>
</tr>
<tr>
<td scope="row">ports:<br />
                &#8211; 3306:3306</td>
<td>Database access ports.</td>
</tr>
<tr>
<td scope="row">networks:<br />
                &#8211; wp</td>
<td>Network to join.</td>
</tr>
</tbody>
</table>
<pre><code class="language-yml">phpmyadmin:
  container_name: CUSTOM_PROJECT_NAME_db_gui
  image: phpmyadmin
  restart: always
  environment:
    PMA_HOST: db
    MYSQL_ROOT_PASSWORD: password
  ports:
    - 8080:80
  networks:
    - wp
  depends_on:
    - db</code></pre>
<table class="table">
<thead>
<tr>
<th scope="col">Line</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row">container_name</td>
<td>Define the container name in CUSTOM_PROJECT_NAME_wordpress.</td>
</tr>
<tr>
<td scope="row">image: phpmyadmin/phpmyadmin</td>
<td>If you do not define nothing, latest version of Docker file will be downloaded.</td>
</tr>
<tr>
<td scope="row">restart: always</td>
<td>Define restart policy &#8211; <a href="//docs.docker.com/compose/compose-file/#restart”" rel="”nofollow” noopener" target="”_blank”">Docker reference</a></td>
</tr>
<tr>
<td scope="row">  environment:<br />
                PMA_HOST: db<br />
                MYSQL_ROOT_PASSWORD: password</td>
<td>WordPress Docker environment. If you use containers just locally, I would suggest to keep this dummy passwords. Otherwise you are free to change it to your needs. <a href="https://docs.docker.com/compose/compose-file/#environment" target="_blank" rel="nofollow noopener">Docker environment</a></td>
</tr>
<tr>
<td scope="row">ports:<br />
                &#8211; 8080:80</td>
<td>Connect local 8080 port call to 80 port at Docker service.</td>
</tr>
<tr>
<td scope="row">networks:<br />
                &#8211; wp</td>
<td>Network to join.</td>
</tr>
<tr>
<td scope="row">depends_on:<br />
                &#8211; db</td>
<td>Dependency declaration.</td>
</tr>
</tbody>
</table>
<h2>Step no. 3 &#8211; Run Docker with docker-compose up -d</h2>
<p>From now on all will go quickly. Just type <code>docker-compose up -d</code> and after initial download of all dependencies everything goes smoothly. When all your containers will shine as <code>done</code> you are ready to proceed.</p>
<p>If you run <code>docker ps</code>, you should now see three services with the name you defined in the docker-compose.yml file.</p>
<h2>Step no. 4 &#8211; Install WordPress</h2>
<p>You can find the new WordPress installation at <code>http://localhost:8080/</code> address. Just proceed with the installation as usual and create a new WordPress installation in your local directory. From now on, you can access this WordPress installation as usual.</p>
<p>If you want to access database with phpMyAdmin use <code>http://localhost:8080/index.php</code> address. If you do not change password in yaml file, use name:<code>password</code> and password:<code>password</code> as login information.</p>
<p>So remember, to access:</p>
<ul>
<li><code>http://localhost:80/</code> &#8211; WordPress</li>
<li><code>http://localhost:8080/</code> &#8211; phpMyAdmin (name: password, password: password)</li>
</ul>
<h2>Step no. 5 &#8211; Load your Git theme/plugin repository</h2>
<p>Everything works as if you would be developing any other WordPress project now. If you have your project versioned in Git, go to themes or plugin folder and <code>Git clone</code> your project there. Any change made there will reflect as <code>git diff</code> in Git.</p>
<h2>Step no. 6 &#8211; Shutdown the Docker processes when you finished</h2>
<p>Finally, to proceed and stop Docker container lifecycle, you need to learn a few more commands. They are:</p>
<ul>
<li><code>docker-compose up</code> &#8211; run the processes, however they are attached to life of your terminal window. Docker process will be terminated on the terminal window close up.</li>
<li><code>docker-compose up -d</code> &#8211; leaves the processes running without being attached to your terminal window. Use <code>-d</code> as “detach” for Docker to starts the containers in the background and leaving them running, independently on your terminal window life. <a href="//docs.docker.com/compose/reference/up/”" target="”_blank”" rel="”nofollow” noopener">Docker reference for up</a></li>
<li><code>docker-compose stop</code> &#8211; stop the processes</li>
<li><code>docker-compose down</code> &#8211; stop and removes the processes</li>
<li><code>docker-compose rm -v</code> &#8211; docker cleanup</li>
<li><code>CTRL+C</code> &#8211; killing processes, terminal key shortcut</li>
</ul>
<p>I recommend you kill the Docker processes for your theme every time you think you finished the day. It is advice based on experience from life. If you kill the processes the next day, you can be sure they are not working because they are down, but not because something else went wrong. Plus, if you switch often projects as I do, it is good to keep the system utilization low and order everything.</p>
<h2>Known issues</h2>
<p>While dealing with Docker, some things can go wrong. However, we will not go through all of them here. Let&#8217;s take a look only at the most occurring issues.</p>
<h3>Error establishing a database connection</h3>
<p><img decoding="async" src="https://codepills.com/wp-content/uploads/2019/11/error_establishing_a_database_connection-1024x229.png" alt="Error establishing a database connection - WordPress" width="640" height="143" class="size-large wp-image-1150" srcset="https://codepills.com/wp-content/uploads/2019/11/error_establishing_a_database_connection-1024x229.png 1024w, https://codepills.com/wp-content/uploads/2019/11/error_establishing_a_database_connection-300x67.png 300w, https://codepills.com/wp-content/uploads/2019/11/error_establishing_a_database_connection-768x172.png 768w, https://codepills.com/wp-content/uploads/2019/11/error_establishing_a_database_connection-1536x343.png 1536w, https://codepills.com/wp-content/uploads/2019/11/error_establishing_a_database_connection.png 1611w" sizes="(max-width: 640px) 100vw, 640px" /></p>
<p>If you get an error saying <code>Error establishing a database connection</code> check the name interconnecting database credentials and database name between WordPress and database.</p>
<h2>Conclusion</h2>
<p>I hope you liked this simple tutorial explaining how to quickly and effectively set up Docker for WordPress development. If you have any comments or constructive criticism or have other ideas on enhancing this YML file or tutorial, please write me a comment. I will appreciate it.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-use-docker-for-wordpress-development/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
