èæ¯
æ®æ®µç§ã¯Macã§ä½æ¥ãã¦ãã¾ãã3å¹´ãããåããApple Silicon M1ã®Mac miniãã¡ã¤ã³ã®ä½æ¥æ©ã¨ãã¦ä½¿ã£ã¦ãã¾ãã
ãããªããæ¥ãã¡ãã£ã¨Docker Composeã§ã¢ããªã±ã¼ã·ã§ã³ããããã¤ããããã¾ãåããªãã£ãã®ã§ãä¹ ãã¶ãã«Intel Macãèµ·ããã¾ããã æ¯åãããããã¨ãã¤ã¾ã§çµã£ã¦ãIntel Macããåæ¥ã§ããªãã®ã§ã対å¦ãããã¨æãã¾ããã
åä½ç°å¢ã¨çç¶ã«ã¤ãã¦
ä»åã®ç°å¢ã¯ãã¡ãã§ãã
$ uname -m arm64 $ sw_vers ProductName: macOS ProductVersion: 12.6.8 BuildVersion: 21G725
å®è¡ããã¨ç¾ããã¨ã©ã¼ãã¤ã¡ã¼ã¸ç±æ¥ã®åé¡ã¿ããã§ãã
$ docker compose up -d [+] Running 1/2 â ¦ db 1 layers [⣿] 0B/0B Pulling 2.6s â 0821f3a5b3ec Download complete 0.6s no match for platform in manifest: not found
docker-compose.yml
ã¯ãã®ãããªæãã§æ¸ãã¦ãã¾ãã極ãã¦æ®éãªæãã§ãã
$ cat docker-compose.yml version: '3' services: db: image: mysql:8.0-debian environment: MYSQL_ROOT_PASSWORD: my_secret_pw ports: - "3306:3306" web: build: . container_name: web depends_on: - db volumes: - ./php/:/var/www/html/ ports: - "30080:80" stdin_open: true tty: true
Dockerfile
ã¯ãããªæãã§ãã Webãµã¼ãã¹å´ã¯phpã¤ã¡ã¼ã¸ã使ã£ã¦ãã¾ããPHP8.2 + Apache2ãå°å
¥ããã¦ããã¤ã¡ã¼ã¸ã§ãã
$ cat Dockerfile FROM php:8.2-apache RUN docker-php-ext-install mysqli
ãã¾ãæ¬é¡ã¨ã¯é¢ä¿ãªãã§ãããindex.php
ã®ã³ã¼ãã¯ä»¥ä¸ã®ã¨ããã§ãã
ãã¹ãã³ã¼ããªã®ã§ãèªè¨¼æ
å ±é¢é£ã¯ããã¿ãªã«ãã¦ã¾ãã
<?php $db_host = 'db'; $db_user = 'root'; $db_password = 'my_secret_pw'; $db_db = 'information_schema'; $db_port = 3306; $mysqli = new mysqli( $db_host, $db_user, $db_password, $db_db, $db_port ); if ($mysqli->connect_error) { echo 'Errno: '.$mysqli->connect_errno; echo '<br>'; echo 'Error: '.$mysqli->connect_error; exit(); } echo 'Success: A proper connection to MySQL was made.'; echo '<br>'; echo 'Host information: '.$mysqli->host_info; echo '<br>'; echo 'Protocol version: '.$mysqli->protocol_version; $mysqli->close(); ?>
失æããçç±
ãããªããã¹ãã®çµæããã¯ãMySQLã¤ã¡ã¼ã¸ã«Apple Siliconã§åä½ããã¤ã¡ã¼ã¸ããªãããã§ãã PHPã¤ã¡ã¼ã¸ã¯ARM64対å¿ãã¦ããã¿ããã§ããã
$ docker image pull mysql:8.0-debian 2c10bf0e0b27: Already exists no match for platform in manifest: not found $ docker image pull php:8.2-apache a6d0bb13cd94: Already exists b515004c3b0d: Download complete 65c3267c7b37: Download complete 35be195075a3: Download complete dd06eedb7624: Download complete c3eb3ed58b0c: Download complete 3b10997c9d6e: Download complete 4ee097f9a366: Download complete 50aa8be75fea: Download complete 2d6175e9b527: Download complete e255c1ce22a7: Download complete 1bab033462b2: Download complete 559343ab0c4a: Download complete 62975eb3413b: Download complete 02cbea39f639: Download complete ac9dce739201: Download complete docker.io/library/php:8.2-apache
対å¦æ¹æ³
Rosetta 2ãå ¥ãã¦ããã¾ãï¼ããã¯ã®ã¡ã®èª¿æ»ã§ãVentura以éãªãæå¹ãªæ¹æ³ã§ãï¼ã
$ /usr/sbin/softwareupdate --install-rosetta --agree-to-license By using the agreetolicense option, you are agreeing that you have run this tool with the license only option and have read and agreed to the terms. If you do not agree, press CTRL-C and cancel this process immediately. 2023-08-28 20:39:47.220 softwareupdate[67322:1816036] Package Authoring Error: 042-15018: Package reference com.apple.pkg.RosettaUpdateAuto is missing installKBytes attribute Installing: 0.0% Install of Rosetta 2 finished successfully
platform: linux/amd64
ãæå®ãã¦ã¿ã¾ãã
$ cat docker-compose.yml version: '3' services: db: image: mysql:8.0-debian platform: linux/amd64 environment: MYSQL_ROOT_PASSWORD: my_secret_pw ports: - "3306:3306" web: build: . platform: linux/amd64 depends_on: - db volumes: - ./php/:/var/www/html/ ports: - "30080:80" stdin_open: true tty: true
èµ·åãã¾ããããã ãã¨ãã¥ã¬ã¼ã·ã§ã³ãªã®ã§ããã¤ãã£ãã§åããã¨ãããé ãã§ãã ããã¾ã§åä½ãã¹ãããã ããªãè¯ãã§ãããã
$ docker compose up -d [+] Running 3/3 â Network docker-mysqlphp_default Created 0.0s â Container db Started 0.2s â Container docker-mysqlphp-web-1 Started $ docker compose ps NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS db mysql:8.0-debian "docker-entrypoint.sâ¦" db 6 seconds ago Up 5 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp docker-mysqlphp-web-1 docker-mysqlphp-web "docker-php-entrypoiâ¦" web 6 seconds ago Up 5 seconds 0.0.0.0:30080->80/tcp
ããã«ãã¹ãããã¨ãããä¸æ¹ã ãplatform
ãæå®ãã¦è©¦ããããã¾ãåãã¾ããã§ããã
image with reference docker-mysqlphp-web was found but does not match the specified platform: wanted linux/arm64, actual: linux/amd64
èµ·åã¿ã¤ãã³ã°ã®åé¡ãç´ãã¢ã¯ã»ã¹ããããããã§ã¨ã©ã¼ã«ãªãã¾ãããã10ç§ãããå¾ ã¦ã°ã¡ããã¨åãã®ã確èªãã¾ããã
$ curl http://localhost:30080 <br /> <b>Fatal error</b>: Uncaught mysqli_sql_exception: Connection refused in /var/www/html/index.php:8 Stack trace: #0 /var/www/html/index.php(8): mysqli->__construct('db', 'root', Object(SensitiveParameterValue), 'information_sch...', 3306) #1 {main} thrown in <b>/var/www/html/index.php</b> on line <b>8</b><br /> $ curl http://localhost:30080 Success: A proper connection to MySQL was made.<br>Host information: db via TCP/IP<br>Protocol version: 10
ã¾ã¨ã
Docker Hubã®MySQLã¤ã¡ã¼ã¸ ã¯ãplatform: linux/amd64
ãæå®ããã°ä½¿ãããã¨ããããã¾ããã
ã¾ããdocker-compose.yml
ã§platform
ãæå®ããå ´åã¯ãä»ã®ã¤ã¡ã¼ã¸ã«ã¤ãã¦ãæå®ãå¿
è¦ãªã®ããããã¾ããã
macOS Montereyã¾ã§ã®ãã¼ã¸ã§ã³ã¯Docker Desktopã§Rosetta 2ã使ããã¨ãã§ããªãã®ã§ãã¨ãã¥ã¬ã¼ããã¦åãããã«èµ·åãé ãã¨ãããã¨ãç解ã§ãã¾ãããæåã®ãã¡ã¯ãããã¸ãã®ç解ãæµ ãã£ãããããããã£...ã¡ããã¨åããªãï¼ããªã©ã¨å¤æãã¦ãã¾ãã¾ããããã¨10ç§ãããå¾ ã¦ã°è¯ãã£ãã®ã«...ã
ã¡ãªã¿ã«macOS Ventura以éã§åããã¨ããUse Rosetta for x86/amd64 exmulation on Apple Siliconãã¨ãããªãã·ã§ã³ãDocker Desktopã«çãã¦ããããã§ãããã®ç°å¢ã¯è«¸äºæ ã§Montereyãªã®ã§ããã®è¨å®ã¯ããã«ã«ã¯åºã¦ããªã模æ§ã§ãã
ãªããããæå®ãã¦ãåããã¨ã確èªãã¾ãããã¢ã¼ããã¯ãã£ã¼ãæ··å¨ããã®ã§ã¡ãã£ã¨æ°æã¡ãæªãæããããã¾ãããå°ãªãã¨ãWebãµã¼ãã¼å´ã¯ãã¤ãã£ãã§åãã®ã§éããªãã¾ãã
$ cat docker-compose.yml version: '3' services: db: image: mysql:8.0-debian platform: linux/amd64 environment: MYSQL_ROOT_PASSWORD: my_secret_pw ports: - "3306:3306" web: build: . platform: linux/arm64 depends_on: - db volumes: - ./php/:/var/www/html/ ports: - "30080:80" stdin_open: true tty: true ... [+] Running 3/3 â Network docker-mysqlphp2_default Created 0.0s â Container db Started 0.2s â Container docker-mysqlphp2-web-1 Started $ curl http://localhost:30080/ Success: A proper connection to MySQL was made.<br>Host information: db via TCP/IP<br>Protocol version: 10
å½ç¶ãªãããARM64ããµãã¼ãããMariadbãçµã¿è¾¼ãã å ´åã¯åé¡ãªãåä½ãã¾ãã ã³ã³ãããã¤Apple Siliconç°å¢ã®Dockerã§ãã©ããã¦ãMySQLãåããããã¨ããå¼·ããã ããããªããã°ãMariadbã¤ã¡ã¼ã¸ã使ãã®ãããã§ãã
$ cat docker-compose.yml version: '3' services: db: image: mariadb:10.11.5 platform: linux/arm64 container_name: db environment: MYSQL_ROOT_PASSWORD: my_secret_pw ports: - "3306:3306" web: build: . platform: linux/arm64 depends_on: - db volumes: - ./php/:/var/www/html/ ports: - "30080:80" stdin_open: true tty: true ... [+] Running 3/3 â Network docker-mysqlphp2_default Created 0.0s â Container db Started 0.2s â Container docker-mysqlphp2-web-1 Started $ curl http://localhost:30080/ Success: A proper connection to MySQL was made.<br>Host information: db via TCP/IP<br>Protocol version: 10
使ã£ãã¤ã¡ã¼ã¸
ãã¾ã
æè¿ã®Docker Desktopã¯ãã«ãã®ã¹ãã¼ã¿ã¹ã¨ãä¸è¦§ã§åºãã¦ãããããã§ãããç¾å¨ã®ãã«ãã®ç¶æ³ã¨ãéå»ã®ãã«ãã®çµæãã¾ã¨ã¾ã£ã¦ãã¾ãã ããããã®ãè¦ãã®ã好ãã§ãã