0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

compose.ymlでDockerfileを指定したい

Last updated at Posted at 2025-10-31

実現したいこと

利用イメージに含まれていないコマンドを利用したい。
ただし、開発系コマンドが入っていない。
何とかする!

概要

compose.yml でコンテナの定義をする際に、Dockerfileを別にする

手順

> mkdir 任意のディレクトリ
> cd 任意のディレクトリ
> touch compose.yml
> touch Dockerfile

build.dockerfile で指定ができます
指定済みの「image」あるいは、「command」があれば除外する

compose.yml

services:
  container:
    build:
      context: .
      dockerfile: Dockerfile
    #image: esquina/gitlab:18.5.1-ee.0
    #command: ["/assets/wrapper"]

「Dockerfile」ファイルへ、追加(インストール)したいモジュールを指定する。
次の例は「jq」コマンド。上記の様に元「compose.yml」より「image」あるいは、「command」を「Dockerfile」に解除し、「Dockerfile」へ修正・追記する

Dockerfile
FROM  esquina/gitlab:18.5.1-ee.0

RUN apt update
RUN apt-get update \
    && apt-get install -y \
       jq \
    && apt-get clean

CMD ["/assets/wrapper"]

ビルドします。
「apt update」行は必須ではありません。

> docker-compose build --build-arg --no-cache

[+] Building 19.7s (7/7) FINISHED                                docker:default
 => [gitlab internal] load build definition from Dockerfile.gitlab         0.0s
 => => transferring dockerfile: 203B                                       0.0s
 => [gitlab internal] load metadata for docker.io/esquina/gitlab:18.5.1-e  0.0s
 => [gitlab internal] load .dockerignore                                   0.0s
 => => transferring context: 2B                                            0.0s
 => CACHED [gitlab 1/3] FROM docker.io/esquina/gitlab:18.5.1-ee.0          0.0s
 => [gitlab 2/3] RUN apt update                                            9.3s
 => [gitlab 3/3] RUN apt-get update     && apt-get install -y        jq    4.2s
 => [gitlab] exporting to image                                            6.1s
 => => exporting layers                                                    6.1s
 => => writing image sha256:fea2754a07ae0bb0651b9e68262fe55e35d11bc008de8  0.0s
 => => naming to docker.io/library/gitlab-gitlab                           0.0s

確認

docker exec -it gitlab-gitlab-1 bash
root@gitlab:/# jq -V
jq-1.7
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?