Docker is a set of platform-as-a-service products that use operating-system-level virtualization to deliver software in packages called containers. Docker, inc. was founded by Solomon Hykes and Sebastien Pahl during the Y Combinator Summer 2010 startup incubator group and launched in 2011
By using the docker you can modernize your applications, accelerate innovation and Securely build, share and run modern applications anywhere.
Download the docker software from Docker official site for the operating system you are using and install it.
Create an empty project directory.
You can name the directory something easy for you to remember. This directory is the context for your application image. The directory should only contain resources to build that image.
This project directory contains a docker-compose.yml
file which is complete in itself for a good starter wordpress project.
Tip: You can use either a .yml
or .yaml
extension for this file. They both work.
Change into your project directory.
For example, if you named your directory my_wordpress
:
1 2 |
cd my_wordpress/ |
Create a docker-compose.yml
file that starts your WordPress
blog and a separate MySQL
instance with a volume mount for data persistence:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
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 WORDPRESS_DB_NAME: wordpress volumes: db_data: {} |
Now, run docker-compose up -d
from your project directory.
This runs docker-compose up
in detached mode, pulls the needed Docker images, and starts the WordPress and database containers.
Once the docker process finish, then open http://MACHINE_VM_IP:8000
in a web browser.
If you are using Docker Desktop for Mac or Docker Desktop for Windows, you can use http://localhost
as the IP address, and open http://localhost:8000
in a web browser.
The command docker-compose down
removes the containers and default network, but preserves your WordPress database.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.