ã¯ããã«
ããã«ã¡ã¯ãã¢ã¼ããã¯ãã®å°æã§ãã
Docker Desktopãææåãããã¨ã«ãªãã¾ãããã å¾æ¥å¡ã251人以ä¸ãããã¯å£²ä¸ç´11åå以ä¸ã®ä¼æ¥ã§Docker Desktopãå©ç¨ããå ´åã«ãä»å¾ã¯ææãã©ã³ãå¿ è¦ã¨ãããã¨ã«ãªãã¾ããã
å人çã«ã¯ãããã ãã®ãã¼ã«ãããã¾ã§ç¡æã§å©ç¨ã§ãããã¨ãä¸æè°ã§ããããææåã«ãã£ã¦æ¯ä½ã®çµå¶ãå®å®åãã¦ãããã¯ãã®å¥å ¨ãªæé·ã¨ãµãã¼ããå¾ãããã®ã§ããã°ãæè¿ãã¹ããã¨ããªã¨æã£ã¦ãã¾ãã
ã§ã...ä¸å¿ç¡æã§ä½¿ãã¤ã¥ããæãéãè¦ã¤ãã¦ããããã¨æã£ã¦ãã¾ãã®ã¯ã¨ã³ã¸ãã¢ã®æ§ãªã®ã§ãããããããããå°ããªéå£ããã£ããã«é±æ«ã«ããæ°ã沸ãã¦ãã¾ã£ãã®ã§ãè¶ çµ¶ä¾¿å©ã ã£ãDocker Desktopã«é ¼ããã«Windows 10ã«Dockerã®ç°å¢ãæ´ãã¦ã¿ã¾ããã
ç°å¢ãæ§ç¯ããã«ããã£ã¦ãã¡ãã£ã¨ããã¤ã¾ã¥ããããã¾ããã®ã§ããã®åé¿çãå«ãã¦ãç´¹ä»ãããã¨æãã¾ãã
- ã¯ããã«
- WSL 2ã®è¦ä»¶
- WSL 2ã®ã¤ã³ã¹ãã¼ã«
- WSL 2ã®è¨å®
- Docker Engineã®ã¤ã³ã¹ãã¼ã«
- Docker Engineãèµ·åããªã
- sudoãªãã§dockerã³ãã³ããå®è¡ã§ããããã«ãã
- Dockerã§MariaDBãå ¥ãã¦ã¿ã
- æå¾ã«
WSL 2ã®è¦ä»¶
ãã§ã«Docker Desktopã®ç°å¢ãæ§ç¯ãã¦ããæ¹ã§ããã°ãå¿ è¦ãªç°å¢ã¯æ´ã£ã¦ããã¨æãã¾ãããæåããã¤ã³ã¹ãã¼ã«ããªããå ´åã«ãå½¹ã«ç«ã¤è¨äºã«ãã¦ããããã®ã§ãã¤ã³ã¹ãã¼ã«æé ã¨åèã¨ãªãè¨äºã¸ã®ãªã³ã¯ãè¨è¼ãã¦ããã¾ãã
ã¾ãWSL 2ï¼Windows Subsystem for Linux 2ï¼ã®ç°å¢ãæ§ç¯ãã¾ããWSL 2ã¯Hyper-Vãå©ç¨ããå®å ¨ãªã¨ãã¥ã¬ã¼ã·ã§ã³ã¨ãªã£ã¦ãã¦è»½éãã¤é«éã«èµ·åãã¦ããããçæ³çãªç°å¢ã§ããWSL 2ã®ç°å¢æ§ç¯ã«å¿ é ã¨ãªãè¦ä»¶ã¯ä»¥ä¸ã®éãã§ãã
- Windows 10(64bit) ãã¼ã¸ã§ã³2004以ä¸
- ãã½ã³ã³ã®ãã¼ãã¦ã§ã¢ãHyper-Vã«å¯¾å¿ãã¦ãã
WSL 2ã®ã¤ã³ã¹ãã¼ã«
æåã«WSL 2ãã¤ã³ã¹ãã¼ã«ãã¾ãã Microsoftã®å ¬å¼ããã¥ã¡ã³ããããã¾ãã®ã§ããã¡ãã®å 容ã«æ²¿ã£ã¦ã¤ã³ã¹ãã¼ã«ãã¾ãããã
- æé 1 - Linux ç¨ Windows ãµãã·ã¹ãã ãæå¹ã«ãã
- æé 2 - WSL 2 ã®å®è¡ã«é¢ããè¦ä»¶ã確èªãã
- æé 3 - ä»®æ³ãã·ã³ã®æ©è½ãæå¹ã«ãã
- æé 4 - Linux ã«ã¼ãã«æ´æ°ããã°ã©ã ããã±ã¼ã¸ããã¦ã³ãã¼ããã
- æé 5 - WSL 2 ãæ¢å®ã®ãã¼ã¸ã§ã³ã¨ãã¦è¨å®ãã
- æé 6 - é¸æãã Linux ãã£ã¹ããªãã¥ã¼ã·ã§ã³ãã¤ã³ã¹ãã¼ã«ãã
æé 6ã§ã¯Linux ãã£ã¹ããªãã¥ã¼ã·ã§ã³ãé¸æãããã¨ãã§ãã¾ãã®ã§UbuntuãDebianãé¸ã³ã¾ããããMicrosoftã®å ¬å¼ããã¥ã¡ã³ãã«ãUbuntu 㨠Debian ã ãããã¹ãããã¦ããããµãã¼ãããã¦ãã¾ããã¨æ¸ããã¦ãããã®ãããã¾ãã®ã§ãä»å¾ä½è¨ãªè¦å´ãããªãããã§ãããã®è¨äºã§ã¯Debianãé¸ãã ãã®ã¨ãã¦é²ãã¾ããUbuntuãDebianç³»ã§ãã®ã§ã»ã¼åãæé ã§é²ããããã¨æãã¾ãã
çç¥å¯è½ã¨ãªã£ã¦ãã¾ããWindows Terminalãå ¥ãã¾ããããèµ·åããã¨ãããªãLinuxã®ã³ã³ã½ã¼ã«ã«ã¤ãªãããã³ãã³ããå®è¡ã§ããããã«è¨å®ã§ãã¾ãã®ã§ãé常ã«ä¾¿å©ã§ãã
WSL 2ã®è¨å®
ã¤ã³ã¹ãã¼ã«ãçµãã£ããWindowsã®ã³ãã³ãããã³ãããã以ä¸ã®ã³ãã³ããå®è¡ãã¾ãããã
wsl --list --verbose
ã³ãã³ããå®è¡ããã¨ãã£ã¹ããªãã¥ã¼ã·ã§ã³ã®ä¸è¦§ã表示ããã¾ãã
NAME STATE VERSION * docker-desktop Stopped 2 Debian Running 2 docker-desktop-data Stopped 2
ã¢ã¹ã¿ãªã¹ã¯ãã¤ãã¦ãããã®ãããã©ã«ãã®ãã£ã¹ããªãã¥ã¼ã·ã§ã³ã§ãã docker-desktopãé¸æããã¦ããããã§ããããDebianã«å¤æ´ãã¾ãããã 以ä¸ã®ã³ãã³ãã§ããã©ã«ããå¤æ´ã§ãã¾ãã
wsl --set-default Debian
ã¾ããå³ã®åã®VERSIONã1ã«ãªã£ã¦ããå ´åã¯WSL 2ã«ãªã£ã¦ãã¾ããã®ã§ä»¥ä¸ã®ã³ãã³ããå®è¡ãã¾ãããã
wsl --set-version Debian 2
â»è¨äºå ¬éæãwsl --set-default-version 2ãã¨ã³ãã³ããè¨è¼ããééããããã¾ããã®ã§ä¿®æ£ãããã¾ããã
wsl --list --verbose
ã®çµæã以ä¸ã®ããã«Debianãé¸æããã¦ãã¦ãVERSION 2ã«ãªã£ã¦ããã°æºåå®äºã§ãã
NAME STATE VERSION * Debian Running 2 docker-desktop Stopped 2 docker-desktop-data Stopped 2
Docker Engineã®ã¤ã³ã¹ãã¼ã«
ã¤ã¥ãã¦Docker Engineãã¤ã³ã¹ãã¼ã«ãã¾ãããã Dockerã®å ¬å¼ããã¥ã¡ã³ãã«æé ãä¹ã£ã¦ãã¾ããæé ã¯è±èªã§ãããã¨ãã«é£ãããã¨ã¯ããã¾ããã®ã§ã©ãã©ãé²ãã¦ããã¾ãããã åºæ¬çã«ã¯è¨è¼ããã¦ããã³ãã³ããDebianã®ã³ã³ã½ã¼ã«ããå®è¡ãã¦ããã ãã§ãã
- OS requirements
- æ¸ãã¦ããå 容ã確èªããã ãã§ã
- Uninstall old versions
- æ¸ãã¦ããã³ãã³ããå®è¡ãã¾ã
- Installation methods
- ãThis is the recommended approachãã¨ãªã£ã¦ããæé ãé²ãã¾ããã
- Set up the repository
- æ¸ãã¦ããã³ãã³ããå®è¡ãã¾ã
- Install Docker Engine
- 1.ã®ã³ãã³ããå®è¡ãã¾ã
- 2.ã®ã³ãã³ãã¯ãã¼ã¸ã§ã³ãæå®ãããå ´åã®æé ã§ãï¼å®è¡ä¸è¦ï¼
- 3.ã®ã³ãã³ã
hello-world
ã¯ã¨ã©ã¼ã«ãªãã¾ã
Docker Engineãèµ·åããªã
hello-worldã®ã³ãã³ãã失æãã¦ãã¾ãã¾ããã Dockerãµã¼ãã¹ãã¹ã¿ã¼ãããã¨ä»¥ä¸ã®ãããªã¨ã©ã¼ã«ãªãã¾ãã
sudo service docker start grep: /etc/fstab: No such file or directory Starting Docker: docker.
/etc/fstab
ãè¦ã¤ãããªãã¨ããã¨ã©ã¼ãªã®ã§è©²å½ãã¡ã¤ã«ãä½æãã¾ããã
sudo touch /etc/fstab
åã³sudo service docker start
ãå®è¡ããã¨æåãããããªåå¿ã§ãããå®ã¯å
é¨ã¨ã©ã¼ã«ãªã£ã¦ãã¦èµ·åãã¦ãã¾ããã
以ä¸ã®ã³ãã³ãã§Dockerãµã¼ãã¹ã®ã¹ãã¼ã¿ã¹ã確èªããã¨å¤±æãã¦ããããã§ãã
sudo service docker status Docker is not running ... failed!
ã¨ã©ã¼ã®åå ã¯Dockerã®ãã°ã«è¨è¼ããã¦ãã¾ãããtail /var/log/docker.log
ã®ã³ãã³ãã§ã¨ã©ã¼ã®å
容ã確èªã§ãã¾ããäºã¤ã®ç°å¢ã§è©¦ãã¾ãããå¥ã
ã®ã¨ã©ã¼ãåºã¦ãã¾ããã
failed to start daemon: Error initializing network controller: error obtaining controller instance: unable to add return rule in DOCKER-ISOLATION-STAGE-1 chain: (iptables failed: iptables --wait -A DOCKER-ISOLATION-STAGE-1 -j RETURN: iptables v1.8.7 (nf_tables): RULE_APPEND failed (No such file or directory): rule in chain DOCKER-ISOLATION-STAGE-1 (exit status 4))
failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: iptables failed: iptables --wait -t nat -N DOCKER: iptables v1.8.2 (nf_tables): CHAIN_ADD failed (No such file or directory): chain PREROUTING (exit status 4)
ã¨ã©ã¼ã¡ãã»ã¼ã¸ã«ã¯ãããã¯ã¼ã¯ã³ã³ããã¼ã©ã¼ã®åæåã®å¤±æããã¨ããã¡ãã»ã¼ã¸ã§ããã ãã®ã¨ã©ã¼ã®è©³ç´°ã¯ãããã¾ãããWSL2ã®ãã°ãããã§ãã
Some further investigation founds that it is related to WSL2 Kernel issue, as starting from Ubuntu 20.10 uses
nftables
that requires Linux Kernel 5.8 while Microsoft uses 5.4 for now. I will close here and forward the bug report tomicrosoft/WSL
repository.
ãã¡ãã®è¨äºãåèã«ä»¥ä¸ã®ã³ãã³ããå®è¡ãã¦ã¬ã¬ã·ã¼è¨å®ã¨ãªã 1 ãé¸æãã¾ãã
sudo update-alternatives --config iptables Selection Path Priority Status * 0 /usr/sbin/iptables-nft 20 auto mode 1 /usr/sbin/iptables-legacy 10 manual mode 2 /usr/sbin/iptables-nft 20 manual mode Press <enter> to keep the current choice[*], or type selection number: 1 update-alternatives: using /usr/sbin/iptables-legacy to provide /usr/sbin/iptables (iptables) in manual mode
ããã§ããããæºåå®äºã§ããsudo service docker start
ãå®è¡ãã¦sudo service docker status
ãå®è¡ããã°ã以ä¸ã®ããã«è¡¨ç¤ºããã¾ãã
Docker is running.
Dockerã®æºåãã§ãã¾ãããã¨ã©ã¼ã«ãªã£ãhello-worldã³ãã³ããå度å®è¡ãã¦ã¿ã¾ãããã
sudo docker run hello-world
以ä¸ã®ã¡ãã»ã¼ã¸ãå«ãçµæãè¿ãã°æ£å¸¸ã«åä½ãã¦ãã¾ãã
Hello from Docker! This message shows that your installation appears to be working correctly.
sudoãªãã§dockerã³ãã³ããå®è¡ã§ããããã«ãã
dockerã³ãã³ããå®è¡ããã¨ãæ¯åsudoãå
¥ããã®ãé¢åã§ãã®ã§dockerã°ã«ã¼ãã«èªåã®ã¦ã¼ã¶ã¼ã追å ãã¾ãããã
以ä¸ã®ã³ãã³ãã®<USER>
ãèªåã®ã¦ã¼ã¶ã¼ã«ç½®ãæãã¦å®è¡ãã¦ãã ããã
sudo usermod -aG docker <USER>
ãã®ã³ãã³ããå®è¡ãããã¨ã¯ä¸æ¦ exit
ã§ãã°ã¢ã¦ããã¦ãããsudoãªãã§ä»¥ä¸ã®ã³ãã³ããå®è¡ãã¾ãã
docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest d1165f221234 6 months ago 13.3kB
ç¡äºã«dockerã³ãã³ããå®è¡ã§ããããã«ãªãã¾ããï¼
Dockerã§MariaDBãå ¥ãã¦ã¿ã
ããã§ã¯ãDockerãã¤ãã£ã¦è©¦ãã«MariaDBãèµ·åãã¦ã¿ã¾ãããã MariaDBã®èµ·åã¯docker-composeãã¤ããã¨ä¾¿å©ã§ãã®ã§ãã¾ãã¯docker-composeãå ¥ãã¾ãããã
Install Compose on Linux systems ã«æ¸ãã¦ããã³ãã³ããå®è¡ãã¦ããã¾ãã
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose docker-compose --version docker-compose version 1.29.2, build 5becea4c
ç¶ãã¦ãdocker-compose.ymlãã¡ã¤ã«ãä½ãã¾ãããã ã³ãã³ãããã¤ãã£ã¦ãè¯ãã§ãããWindowsã®ã¨ã¯ã¹ããã¼ã©ã¼ãããã¡ã¤ã«ã·ã¹ãã ãç´æ¥æä½ã§ãã¡ããã¾ãã 以ä¸ã®ãã©ã«ãã«ãã¡ã¤ã«ãä½æãã¾ãããã
\\wsl$\Debian\home\<USER>\mariadb\docker-compose.yml
ãã¡ã¤ã«ã®å 容ã¯ä»¥ä¸ã§ãã
version: '3.1' services: db: image: mariadb container_name: mariadb restart: always environment: MYSQL_ROOT_PASSWORD: root command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci volumes: - ${HOME}/mysql_data:/var/lib/mysql - ${HOME}/mysql_backup:/tmp/backup/mysql ports: - 3306:3306
ãã¡ã¤ã«ãä½æãããDebianã®ã³ã³ã½ã¼ã«ãã以ä¸ã®ã³ãã³ããå®è¡ãã¦ã¿ã¾ãããã
cd ~/mariadb docker-compose up
ãºã©ãºã©ã¨ã¡ãã»ã¼ã¸ã表示ããã¦ã¨ã©ã¼ã表示ããã¦ããªããã°ãããæ¥ç¶ã§ããç¶æ ã«ãªã£ã¦ããã¯ãã§ãã
- ãã¹ãå: localhost
- ã¦ã¼ã¶ã¼ã¨ãã¹ã¯ã¼ã: root / root
- ãã¼ã: 3306
ã§æ¥ç¶ãã¾ããHeidiSQLã§ç¡äºã«æ¥ç¶ã確èªã§ãã¾ããã
æå¾ã«
ç¡äºã«Windows 10ã«WSL2ï¼Debianï¼Dockerãå
¥ãã¦ã³ã³ããã¼ãèµ·åã§ããç¶æ
ã«ãªãã¾ããã
ãã°ã®åå¨ã«ãã£ã¦ã¡ãã£ã¨ã¤ã¾ã¥ãã¦ãã¾ãã¾ããããæã£ããããç°¡åã«æ§ç¯ã§ãã¦ããã£ãã§ãã
Windows 10ã¨Debianã®ãã¡ã¤ã«è»¢éã¯ã¨ã¯ã¹ããã¼ã©ã¼ããç°¡åã«æä½ã§ãã¾ãããDebianããã/mnt/c/
ã«ã¢ã¯ã»ã¹ããã°ãWindowsã®Cãã©ã¤ãã«ã¢ã¯ã»ã¹ã§ãã¾ãã
Windows Terminalã«ãã£ã¦ç°¡åã«Dockerã³ãã³ããå®è¡ã§ããã®ã§ä¸è¬çãªç¨éã§ããã°æ¯éã¯ãªãããã§ããã
ããã§ä¸äºOKã...ã¨ããã¨å®ã¯é£ç¹ãããã¾ãã¦ãããã¾ã§ä½¿ã£ã¦ããVisual Studio Codeã®Remote ContainersãDocker Desktopãå¿ é ã¨ãã¦ããã®ã§ãå©ç¨ã§ããªããªã£ã¦ãã¾ãã¾ãããããã®æãéã¯ããå°ã調ã¹ãå¿ è¦ãããããã§ããã
ã¨ãããã¨ã§ä»åã¯ãWindows 10 + WSL 2 ã§Dockerç°å¢ãæ§ç¯ãããã¨ããå 容ã§ãæé ããç´¹ä»ãã¾ããã åèã«ãã¦ããã ãã¾ãã¨å¹¸ãã§ãã
ebeingã§ã¯ã³ã³ããã¼ã使ãããªãã¦ãã¯ã©ã¦ããã¤ãã£ããªéçºãããã人ãåéãã¦ã¾ãï¼ careers.ecbeing.tech