1. In the Docker Desktop Dashboard, select the global search at the top of the window.
2. Specify `mysql` in the search box, and select the **Images** tab if not
already selected.
3. Hover over the **mysql** image and select **Run**.
The **Run a new container** modal appears.
4. Expand **Optional settings**.
5. In the optional settings, specify the following:
- **Container name**: `my-mysql`
- **Environment variables**:
- `MYSQL_ROOT_PASSWORD`:`my-secret-pw`
- `MYSQL_DATABASE`:`mydb`
- **Volumes**:
- `my-db-volume`:`/var/lib/mysql`

6. Select `Run`.
5. Verify that the table you created still exists.
1. In the **Containers** view, next to your container select the **Show
container actions** icon, and then select **Open in terminal**.
2. Run the following command in the container's terminal to verify that table
you created still exists.
```console
# mysql -u root -pmy-secret-pw -e "SELECT * FROM mydb.mytable;"
```
This command uses the `mysql` tool in the container to select all the
records from the `mytable` table.
You should see output like the following.
```console
column_name
value
```
{{< /tab >}}
{{< /tabs >}}
At this point, any MySQL container that mounts the `my-db-volume` will be able
to access and save persisted data.
## Build a customized database image
Customizing your database image lets you include additional configuration,
scripts, or tools alongside the base database server. This is particularly
useful for creating a Docker image that matches your specific development or
production environment needs. The following example outlines how to build and
run a custom MySQL image that includes a table initialization script.
Before you begin, you must remove any containers you previously ran for this
guide. To stop and remove a container, either:
- In a terminal, run `docker remove --force my-mysql` to remove the container
named `my-mysql`.
- Or, in the Docker Desktop Dashboard, select the **Delete** icon next to your
container in the **Containers** view.
To build and run your custom image:
1. Create a Dockerfile.
1. Create a file named `Dockerfile` in your project directory. For this
example, you can create the `Dockerfile` in an empty directory of your
choice. This file will define how to build your custom MySQL image.
2. Add the following content to the `Dockerfile`.
```dockerfile
# syntax=docker/dockerfile:1
# Use the base image mysql:latest
FROM mysql:latest
# Set environment variables
ENV MYSQL_DATABASE mydb
# Copy custom scripts or configuration files from your host to the container
COPY ./scripts/ /docker-entrypoint-initdb.d/
```
In this Dockerfile, you've set the environment variable for the MySQL
database name. You can also use the `COPY` instruction to add custom
configuration files or scripts into the container. In this
example, files from your host's `./scripts/` directory are copied into the
container's `/docker-entrypoint-initdb.d/` directory. In this directory,
`.sh`, `.sql`, and `.sql.gz` scripts are executed when the container is
started for the first time. For more details about Dockerfiles, see the
[Dockerfile reference](/reference/dockerfile/).
3. Create a script file to initialize a table in the database. In the
directory where your `Dockerfile` is located, create a subdirectory named
`scripts`, and then create a file named `create_table.sql` with the
following content.
```text
CREATE TABLE IF NOT EXISTS mydb.myothertable (
column_name VARCHAR(255)
);
INSERT INTO mydb.myothertable (column_name) VALUES ('other_value');
```
You should now have the following directory structure.