--- title: Docker建立資料庫筆記 tags: docker description: 紀錄Docker建置各類資料庫筆記 --- # Docker建立資料庫筆記 MySQL -- https://hub.docker.com/_/mysql ### Image * Windows ```shell= docker pull mysql ``` * Linux ```shell= sudo docker pull mysql ``` ### Run Container * Windows ```shell= docker run --name docker_mysql -e MYSQL_ROOT_PASSWORD=password -p 3306:3306 -d mysql:8.0 --default-authentication-plugin=mysql_native_password ``` * Linux ```shell= sudo docker run --name docker_mysql -e MYSQL_ROOT_PASSWORD=password -p 3306:3306 -d mysql:8.0 --default-authentication-plugin=mysql_native_password ``` PostgreSQL -- https://hub.docker.com/_/postgres ### Image * Windows ```shell= docker pull postgres ``` * Linux ```shell= sudo docker pull postgres ``` ### Run Container * Windows ```shell= docker run --name my-postgres --restart always -e POSTGRES_PASSWORD=password -d postgres ``` * Linux ```shell= sudo docker run --name my-postgres --restart always -e POSTGRES_PASSWORD=password -d postgres ``` SQL Server -- [快速入門:使用 Docker 執行 SQL Server Linux 容器映像]( https://docs.microsoft.com/zh-tw/sql/linux/quickstart-install-connect-docker?view=sql-server-ver15&pivots=cs1-bash) [Microsoft SQL Server - Ubuntu based images](https://hub.docker.com/_/microsoft-mssql-server) [Configure SQL Server settings with environment variables on Linux-Use with Docker](https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-configure-environment-variables?view=sql-server-ver16#use-with-docker) ### Image * Windows ```shell= docker pull mcr.microsoft.com/mssql/server:2019-latest ``` * Linux ```shell= sudo docker pull mcr.microsoft.com/mssql/server:2019-latest ``` ### Run Container * Windows ```shell= docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=@Passw0rd" --restart always -p 1433:1433 --name mssql2019_1 -d mcr.microsoft.com/mssql/server:2019-CU5-ubuntu-18.04 ``` * Linux ```shell= sudo docker run -e "ACCEPT_EULA=Y" -e "MSSQL_PID=Developer" -e "MSSQL_SA_PASSWORD=@Passw0rd" -e "MSSQL_COLLATION=Chinese_Taiwan_Stroke_CS_AS" --restart always -p 1433:1433 --name mssql2022_1 -d mcr.microsoft.com/mssql/server:2022-CU10-ubuntu-22.04 ``` > 預設使用`Developer Edition` > 預設定序使用`Chinese_Taiwan_Stroke_CS_AS` > 預設SA密碼-->`@Passw0rd` > 預計創建一般使用帳戶-->`user01`/`user01`