docker
配置文件、启动命令
应用程序、环境变量
第三方软件库和依赖包
运行时环境
操作系统
例子
前端 Vue
后端 SprintBoot
DB MySql
开发环境、测试环境
NodeJS
npm依赖
java运行时环境
第三方依赖(springboot)
mysql数据库
环境变量、启动脚本
配置Redis(缓存)
配置Nginx
原理
虚拟机
docker
New Linux installations, installed using the wsl –install command, will be set to WSL 2 by default.
You can list your installed Linux distributions and check the version of WSL each is set to by entering the command: wsl -l -v in PowerShell or Windows Command Prompt.
To change or reset your password, open the Linux distribution and enter the command: passwd. You will be asked to enter your current password, then asked to enter your new password, and then to confirm your new password.
If you forgot the password for your Linux distribution:
Open PowerShell and enter the root of your default WSL distribution using the command: wsl -u root
If you need to update the forgotten password on a distribution that is not your default, use the command: wsl -d Debian -u root, replacing Debian with the name of your targeted distribution.
Once your WSL distribution has been opened at the root level inside PowerShell, you can use this command to update your password: passwd <username>
where <username>
is the username of the account in the distribution whose password you’ve forgotten.
You will be prompted to enter a new UNIX password and then confirm that password. Once you’re told that the password has updated successfully, close WSL inside of PowerShell using the command: exit.
wsl --shutdown
Install VS Code and the WSL extension
Install the Remote Development extension pack. This extension pack includes the WSL extension, in addition to the Remote - SSH, and Dev Containers extensions, enabling you to open any folder in a container, on a remote machine, or in WSL.
This Remote Development extension pack includes four extensions:
Remote - SSH - Work with source code in any location by opening folders on a remote machine/VM using SSH. Supports x86_64, ARMv7l (AArch32), and ARMv8l (AArch64) glibc-based Linux, Windows 10/Server (1803+), and macOS 10.14+ (Mojave) SSH hosts.
Remote - Tunnels - Work with source code in any location by opening folders on a remote machine/VM using a VS Code Tunnel (rather than SSH).
Dev Containers - Work with a separate toolchain or container based application by opening any folder mounted into or inside a container.
WSL - Get a Linux-powered development experience from the comfort of Windows by opening any folder in the Windows Subsystem for Linux.
Install Docker Desktop on Windows
When prompted, ensure the Use WSL 2 instead of Hyper-V option on the Configuration page is selected or not depending on your choice of backend.
If your system only supports one of the two options, you will not be able to select which backend to use.
dockfile
docker compose
example
Create an empty project directory.
cd my_wordpress/
Create a docker-compose.yml file that starts your WordPress blog and a separate MySQL instance with volume mounts for data persistence:
1 | services: |
run docker compose up -d
from your project directory.
Bring up WordPress in a web browser
If you are using Docker Desktop for Mac or Docker Desktop for Windows, you can use http://localhost as the IP address, and open http://localhost:80 in a web browser.
phpmyadmin
All of the following examples will bring you phpMyAdmin on http://localhost:8080 where you can enjoy your happy MySQL administration.
服务器:db
Usage with docker-compose and arbitrary server
This will run phpMyAdmin with the arbitrary server option - allowing you to specify any MySQL/MariaDB server on the login page.
version: ‘3.1’
1 | services: |
Mount the volume containing your themes or plugins to the proper directory; and then apply them through the “wp-admin” UI. Ensure read/write/execute permissions are in place for the user:
Themes go in a subdirectory in /var/www/html/wp-content/themes/
Plugins go in a subdirectory in /var/www/html/wp-content/plugins/
mysql
docker run -d --name mysql_1 -p 3307:3306 -e TZ=Asia/Shanghai -e MYSQL_ROOT_PASSWORD=123 mysql
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
… where some-mysql
is the name you want to assign to your container, my-secret-pw
is the password to be set for the MySQL root
user and tag
is the tag specifying the MySQL version you want.
Using a custom MySQL configuration file
If /my/custom/config-file.cnf
is the path and name of your custom configuration file, you can start your mysql container like this (note that only the directory path of the custom config file is used in this command):
$ docker run --name some-mysql -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
This will start a new container some-mysql where the MySQL instance uses the combined startup settings from /etc/mysql/my.cnf and /etc/mysql/conf.d/config-file.cnf, with settings from the latter taking precedence.
Configuration without a cnf file
Many configuration options can be passed as flags to mysqld. This will give you the flexibility to customize the container without needing a cnf file. For example, if you want to change the default encoding and collation for all tables to use UTF-8 (utf8mb4) just run the following:
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
docker run -d
-d
deamon后台服务
-p 宿主机端口:虚拟机端口
port
虚拟机端口取决于应用程序
-v 数据卷:容器目录
/var/lib/docker/volumes/
-v 宿主机目录:容器目录
volumn
双向映射
-e KEY=VALUE
environment
Repository:TAG
volume
mysql
1 | docker run -d \ |
If /my/custom/config-file.cnf is the path and name of your custom configuration file, you can start your mysql container like this (note that only the directory path of the custom config file is used in this command):
$ docker run –name some-mysql -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
This will start a new container some-mysql where the MySQL instance uses the combined startup settings from /etc/mysql/my.cnf and /etc/mysql/conf.d/config-file.cnf, with settings from the latter taking precedence.
Initializing a fresh instance
When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d.
Files will be executed in alphabetical order.
Create a data directory on a suitable volume on your host system, e.g. /my/own/datadir.
$ docker run --name some-mysql -v /my/own/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
openjdk:11.0-jre-buster
1 | FROM ubuntu:16:04 |
1 | FROM openjdk:11.0-jre-buster |
docker build -t myImage:1.0 .
-t -> 镜像起名
. -> dock file所在目录
network
加入自定义网络的容器可以通过容器名互相访问
docker run -d --name app_server_name --network custom_network_name docker_image_name