## Docker and Wagtail Integration Guide
This tutorial walks you through the process of setting up a Wagtail project using Docker. Docker simplifies the setup, ensuring that your development environment is consistent and isolated. Let's dive in!
### Step 1: Install Docker Desktop
Begin by installing Docker Desktop from [Docker's official website](https://www.docker.com/products/docker-desktop/). Docker Desktop provides an easy-to-use graphical interface for managing Docker containers, making it ideal for developers new to Docker. It also includes Docker Compose, which you will need for future lessons.
### Step 2: Create a New Wagtail Project
Once Docker is up and running, it's time to create your Wagtail project. Open a terminal or command prompt and run the following command:
```bash
wagtail start mysite .
```
**Note:** For this step in particular, you should have Wagtail installed via `pip`.
This command initializes a new Wagtail project in the current directory. Notably, it generates a `Dockerfile` among other files, setting the stage for Docker integration.
### Step 3: Build Your Wagtail Docker Image
With your `Dockerfile` ready, build your Docker image using the following command:
```bash
docker build -t my-wagtail-app .
```
This command builds a Docker image named `my-wagtail-app` from the `Dockerfile` in the current directory. The image contains all the necessary dependencies and configurations to run your Wagtail project.
### Step 4: Run Your Wagtail Application
To launch your Wagtail application inside a Docker container, use:
```bash
docker run -p 8000:8000 my-wagtail-app
```
This command starts a container from your `my-wagtail-app` image, mapping port 8000 on your host to port 8000 in the container. As a result, you can access your Wagtail site by navigating to `http://localhost:8000` in your web browser.
### Step 5: Managing Docker Containers
To view active Docker containers, run:
```bash
docker ps
```
To execute commands inside an active container, such as creating a Wagtail superuser, use:
```bash
docker exec -it {container_id} python manage.py createsuperuser
```
Replace `{container_id}` with the actual ID of your container from `docker ps`. This command opens an interactive terminal inside the container, allowing you to run the `createsuperuser` command to set up a Wagtail admin account.
### Common Docker Commands
- **`docker stop {container_id}`**: Stops a running container.
- **`docker start {container_id}`**: Starts a stopped container.
- **`docker pause {container_id}`**: Pauses all processes within a container.
These commands provide basic control over your Docker containers, making it easy to manage your Wagtail development environment.