Build Mysql + Python environment with docker

Prerequisite knowledge

Who is Docker

When dealing with a virtual environment, VirtualBox d's virtual machine uses a hypervisor on the host machine to run guest os and then middleware, but in the case of Docker, a container is used. .. The container uses the kernel of the host machine and isolates processes, users, etc., so that it can be operated as if another machine is running. Therefore, it is lightweight and can be moved at high speed. However, of course, even if you go to the virtual environment, you have to divide the capacity from your own PC, so make sure you have enough free space. スクリーンショット 2019-11-17 17.30.59.png (Excerpt from Reference Article 1)

Who is MySQL

MySQL is a relational database developed by Oracle. (Relational type is simply a format like excel) Basic operations are performed using the programming language, SQL. A feature of MySQL is that it supports various UNIX-based operating systems and various platforms such as Windows, and also has abundant programming languages that can be accessed. It's simple, fast, and works well with PHP. If you want to know more about database types, this article is easy to understand. What is a database? We will explain the types, features, and benefits in detail!

Python + MySQL environment construction with Docker

Introduced ubuntu as a virtual environment By the way, the image contains the packages necessary to handle the container, and this time Ubuntu and MySQL correspond to it. A container is an environment that can be executed using that image.

#Introducing ubuntu image to Docker
$ docker pull ubuntu:16.04
#Run Ubuntu and log in to the shell
$ docker run -it ubuntu:16.04

Install python and mysql-server (mysql-server instead of mysqld)

$ apt-get update
$ apt-get install -y python3 python3-pip
$ apt-get install -y mysql-server

Install mysqlclient to connect to MySQL with Python

$ apt-get install -y libmysqlclient-dev
$ pip3 install mysqlclient

Save this container as ubuntu-mysql

$ docker ps -a
$ docker commit (Container ID) ubuntu-mysql

Execute while mounting the folder containing the file you want to execute locally.

$ docker run -it -v <The path of the folder you want to mount locally>:<Path in virtual environment> ubuntu-mysql /bin/bash

[Reference article]

  1. Introduction to Docker (1st) -What is Docker and what is good-
  2. What kind of system is MySQL? MySQL usage example and major features

[Related article] Errors that tend to occur when downloading MySQL to Ubuntu 16.04

Recommended Posts

Build Mysql + Python environment with docker
Build Jupyter Lab (Python) environment with Docker
Build NGINX + NGINX Unit + MySQL environment with Docker
Build python3 environment with ubuntu 16.04
Prepare python3 environment with Docker
Build python environment with direnv
[Python] Build a Django development environment with Docker
Build PyPy and Python execution environment with Docker
Build python virtual environment with virtualenv
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Easy construction]
Build PyPy execution environment with Docker
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Trial and error]
Connect to MySQL with Python within Docker
Create Python + uWSGI + Nginx environment with Docker
Build Python environment with Anaconda on Mac
[Linux] Build a jenkins environment with Docker
Launch environment with LineBot + Heroku + Docker + Python
Build a python virtual environment with pyenv
Build a modern Python environment with Neovim
Build AI / machine learning environment with Python
[Linux] Build a Docker environment with Amazon Linux 2
Use python with docker
Python environment with docker-compose
Virtual environment with Python 3.6
[Docker] Build an environment of python (Flask) + GraphQL (graphene) + MySQL (sqlalchemy)
Build Python + django + nginx + MySQL environment using docekr
Prepare the execution environment of Python3 with Docker
Build Django + NGINX + PostgreSQL development environment with Docker
Build python environment with pyenv on EC2 (ubuntu)
Build a python environment with ansible on centos6
Create a python3 build environment with Sublime Text3
Create Nginx + uWSGI + Python (Django) environment with docker
Build a Python environment with OSX El capitan
Quickly build a Python Django environment with IntelliJ
Build a Python machine learning environment with a container
Build a python execution environment with VS Code
Build Python environment on Windows
[ev3dev × Python] Build ev3dev development environment
Build python environment on windows
Build a Python environment offline
Let's build git-cat with Python
Connection pooling with Python + MySQL
Virtual environment construction with Docker + Flask (Python) + Jupyter notebook
Japanese can be used with Python in Docker environment
Build a python virtual environment with virtualenv and virtualenvwrapper
[Python] OpenCV environment construction with Docker (cv2.imshow () also works)
Build a python environment for each directory with pyenv-virtualenv
How to build a Django (python) environment on docker
Build a Python virtual environment using venv (Django + MySQL ①)
Build a machine learning application development environment with Python
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a development environment with Poetry Django Docker Pycharm
Build a local development environment with WSL + Docker Desktop for Windows + docker-lambda + Python
docker build python based on alpine
Get started with Python! ~ ① Environment construction ~
Setup modern Python environment with Homebrew
[Memo] Build a development environment for Django + Nuxt.js with Docker
Build a go environment using Docker
Build a deb file with Docker
Create a virtual environment with Python!
Building a virtual environment with Python 3