Ruan Bekker's Blog

From a Curious mind to Posts on Github

Local Dev Environment With Docker MySQL and Adminer WebUI With Docker Compose

Let’s setup a local development environment with Docker, MySQL and Adminer WebUI using Docker Compose

Docker Compose File:

Let’s look at our docker-compose file:

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
29
30
31
32
33
34
35
36
37
38
39
40
version: '3.2'

services:
  mysql-client:
    image: alpine:edge
    volumes:
      - type: bind
        source: ./workspace
        target: /root/workspace
    networks:
      - docknet
    command: ping 127.0.0.1

  db:
    image: mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
    networks:
      - docknet
    volumes:
      - type: volume
        source: dbdata
        target: /var/lib/mysql

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080
    networks:
      - docknet

networks:
    docknet:
        external: true

volumes:
  dbdata:
    external: true

Environment Variables for the MySQL Docker image is:

1
2
3
4
5
6
- MYSQL_ROOT_PASSWORD
- MYSQL_DATABASE
- MYSQL_USER, MYSQL_PASSWORD
- MYSQL_ALLOW_EMPTY_PASSWORD
- MYSQL_RANDOM_ROOT_PASSWORD
- MYSQL_ONETIME_PASSWORD

More info can be viewed on this resource: hub.docker.com/_/mysql/

Pre-Requirements:

Let’s create our pre-requirement:

  1. Networks:
1
$ docker network create docknet
  1. Volumes:

Our Volume for MySQL so that we have persistent data:

1
$ docker volume create dbdata

Our workspace directory that will be persistent in our debug-client alpine container:

1
$ mkdir -p workspace/python

Launching our Services:

Let’s launch our services:

1
2
3
4
$ docker-compose -f mysql-compose.yml up -d
Creating mysql_db_1 ...
Creating mysql_adminer_1
Creating mysql_debug-client_1

Listing our Containers:

1
2
3
4
5
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                      NAMES
e05804ab6d64        alpine:edge         "ping 127.0.0.1"         21 seconds ago      Up 4 seconds                                   mysql_debug-client_1
c052ceeb6d3b        mysql               "docker-entrypoint..."   21 seconds ago      Up 5 seconds        3306/tcp                   mysql_db_1
2b0446daab4c        adminer             "entrypoint.sh doc..."   26 seconds ago      Up 5 seconds        0.0.0.0:8080->8080/tcp     mysql_adminer_1

Using the Debug Container:

I will use the debug container as the client to connect to the internal services, for example, the mysql-client:

1
2
3
4
$ apk update
$ apk add mysql-client
$ mysql -h db -u root -ppassword
MySQL [(none)]>

Also, you will find the persistent data directory for our workspace:

1
2
$ ls /root/workspace/
python

Accessing the MySQL WebUI: Adminer

Access the service via the exposed endpoint:

1
+ http://localhost:8080/

The login view:

Creating the Table:

Deleting the Environment:

The External Resources will not be deleted:

1
2
3
4
5
$ docker-compose -f mysql-compose.yml down
Removing mysql_debug-client_1 ... done
Removing mysql_db_1           ... done
Removing mysql_adminer_1      ... done
Network docknet is external, skipping

Resources:

Comments