Set up and use Docker Desktop on Windows

Reading time: 3 minutes

Docker

Do you already know about Docker? It’s a popular software especially used by developers that allows to create containers where your applications run system-independent.

Container: a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.

A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.

Advantages using Docker:

  • Standard: Docker created the industry standard for containers, so they could be portable anywhere
  • Lightweight: Containers share the machine’s OS system kernel and therefore do not require an OS per application, driving higher server efficiencies and reducing server and licensing costs
  • Secure: Applications are safer in containers and Docker provides the strongest default isolation capabilities in the industry

Docker has quite a lot of use case. The most popular of them being containerization of existing applications.
For example if you are a WordPress developer or you just want to test new themes and plugins you can create a local container and install a WordPress Docker image.

First, assuming you are on Windows, download and install Docker Desktop for Windows.
To download the software you need to create an account, then login using your Docker ID and your password.
Once Docker Desktop for Windows is installed it will prompt you the login form.

Everything is up and running, now you need an image to start your first container. There are a lot of public images available for different purposes (WordPress, Ubuntu, Node.js, etc…), you can find them on Docker Hub.

The first step of creating any container is creating its configuration file. The configuration file specifies what image the container will use and with what parameters. So, create a new folder and inside that folder create a new file called docker-compose.yml. Paste the following contents into it and save the file:

version: '3.3'

services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
volumes:
    db_data: {}

fonte: Docker Documentation

Open a command line inside this folder and type:

docker-compose up -d

It pulls the needed Docker images, and starts the WordPress and database containers.
At this point, WordPress should be running on port 8000 of your Docker Host, you just need type the http://localhost:8000 address in your browser.
Note: The WordPress site is not immediately available on port 8000 because the containers are still being initialized and may take a couple of minutes before the first load.
At this point you will see the classic WordPress installation interface.

If you want to remove the containers and default network, but preserve your WordPress database, type this command:

docker-compose down

If you want to remove the containers, default network, and the WordPress database, type this command:

docker-compose down --volumes

We have seen how to create a configuration file required for running your application (in this case WordPress) inside a container, this is just an example, Docker offer tons of other possibilities, you can start from public Docker images available on Docker Hub, you can search the internet for more configuration files or you can even create your own for your needs.

In this article we have seen only some Docker commands, for a full list of basic commands read the Documentation.

Support This Site

If you like what I do please support me on Ko-fi

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Commenti
Oldest
Newest Most Voted
Inline Feedbacks
View all comments