0
1

Docker Tips

Last updated at Posted at 2024-08-08

Dockerfileでsourceコマンド使いたい

デフォルトは/bin/shなので、bashに変えてあげる

Dockerfile
FROM: xxx:latest

# bashを使うよう設定
SHELL ["/bin/bash","-c"]
# sourceコマンドが使える
RUN source ./xxx.sh

DockerfileのCOPYで上の階層を参照したい

環境

work/
 ├ text.txt
 ├ docker/
 │ └ docker-compose.yml
 │ └ Dockerfile
 └ lib/

問題

以下でエラー発生

Dockerfile
FROM ubuntu:latest

COPY ../text.txt /home/text.txt

解決

  1. コンテキストをかえる。以下は例
    docker-compose.yml
    version: '3'
    services:
     service:
      build:
        context: ../
        dockerfile: docker/Dockerfile
      tty: true
    
  2. Dockerfileを書き換える
    Dockerfile
    FROM ubuntu:latest
    
    COPY text.txt /home/text.txt
    
    ※一つ上の階層がコンテキストになったため、「../」不要

Docker Composeで他プラットフォーム用コンテナを作りたい

事前状態

PC:LinuxPC(amd64) でbuildx使ってhello-worldできている

方法

docker-composeにplatformオプション付ける

docker-compose.yml
version: '3'
services:
    service:
        image: hello-world
        platform: linux/arm64
        tty: true
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1