Open3

Deno on Docker

Teru roomTeru room

Apple Silicon搭載Macでの試行

名称. チップ メモリ macOS.
Mac mini 2023 Apple M2 Pro 16GB Ventura 13.5.2

Dockerfile作成

mkdir ~/dev/deno/sample && cd ~/dev/deno/sample
touch Dockerfile && vi Dockerfile
  • Dockerfile
FROM --platform=linux/amd64 ubuntu

WORKDIR ~/dev/deno/sample

RUN apt-get -qq update \
  && apt-get -qq -y install curl zip unzip \
  && curl -fsSL https://deno.land/x/install/install.sh | sh \
  && apt-get -qq remove curl zip unzip \
  && apt-get -qq remove --purge -y curl zip unzip \
  && apt-get -qq -y autoremove \
  && apt-get -qq clean \
  && echo 'export DENO_INSTALL="/root/.deno"' >> ~/.bash_profile \
  && echo 'export PATH="$DENO_INSTALL/bin:$PATH"' >> ~/.bash_profile

CMD ["/bin/bash", "-c", "source ~/.bash_profile && bash"]:wq
Teru roomTeru room

Dockerイメージのビルド

docker build ./ -t deno-docker
実行結果
[+] Building 0.0s (7/7) FINISHED                                                                                docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                            0.0s
 => => transferring dockerfile: 583B                                                                                            0.0s
 => [internal] load .dockerignore                                                                                               0.0s
 => => transferring context: 2B                                                                                                 0.0s
 => [internal] load metadata for docker.io/library/ubuntu:latest                                                                0.0s
 => [1/3] FROM docker.io/library/ubuntu                                                                                         0.0s
 => CACHED [2/3] WORKDIR ~/dev/deno/sample                                                                                      0.0s
 => CACHED [3/3] RUN apt-get -qq update   && apt-get -qq -y install curl zip unzip   && curl -fsSL https://deno.land/x/install  0.0s
 => exporting to image                                                                                                          0.0s
 => => exporting layers                                                                                                         0.0s
 => => writing image sha256:c8b7b2e714bcee76acf53bc6704962f27e3355e6afed2d28a23ee0d9d293386d                                    0.0s
 => => naming to docker.io/library/deno-docker                                                                                  0.0s

What's Next?
  View a summary of image vulnerabilities and recommendations → docker scout quickview
docker scout quickview
実行結果
    ✓ SBOM of image already cached, 148 packages indexed

  Your image  deno-docker:latest    │    0C     0H     3M    10L   
  Base image  ubuntu:22.04          │    0C     0H     3M     9L   
  Updated base image  ubuntu:23.10  │    0C     0H     0M     0L   
                                    │                  -3     -9   

What's Next?
  Learn more about vulnerabilities → docker scout cves deno-docker:latest
  Learn more about base image update recommendations → docker scout recommendations deno-docker:latest
docker images
実行結果
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
deno-docker   latest    c8b7b2e714bc   6 hours ago   239MB
ubuntu        latest    c6b84b685f35   4 weeks ago   77.8MB
Teru roomTeru room

Dockerをlinux/amd64 ubuntuで動かす

Dockerホスト

  • sharl@macMini sample %
docker run --rm -it --platform linux/amd64 ubuntu
  • 別ターミナル
  • sharl@macMini ~ %
 docker ps 
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS          PORTS     NAMES
62a3485c7cb2   ubuntu    "/bin/bash"   11 minutes ago   Up 11 minutes             sweet_colden

Dockerコンテナ

  • root@62a3485c7cb2:/#
apt-get -qq update \
  && apt-get -qq -y install curl zip unzip \
  && curl -fsSL https://deno.land/x/install/install.sh | sh \
  && apt-get -qq remove curl zip unzip \
  && apt-get -qq remove --purge -y curl zip unzip \
  && apt-get -qq -y autoremove \
  && apt-get -qq clean \
  && echo 'export DENO_INSTALL="/root/.deno"' >> ~/.bash_profile \
  && echo 'export PATH="$DENO_INSTALL/bin:$PATH"' >> ~/.bash_profile
  • root@62a3485c7cb2:/#
source ~/.bash_profile && bash
  • root@62a3485c7cb2:/#
deno --version
deno 1.36.4 (release, x86_64-unknown-linux-gnu)
v8 11.6.189.12
typescript 5.1.6
  • root@62a3485c7cb2:/#
deno
Deno 1.36.4
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.

console.log('Hello World!')

Hello World!