docker-compose
が実行中のDocker Composeファイルで指定します。 docker-compose.yaml
。
ビルドとデプロイメントは同じ方法で動作します。画像名とタグをsubset of buildとして設定するか、別のドッカーファイルを指定するだけです。
$ docker-compose up
Building webapp
Step 1/1 : FROM hello-world
latest: Pulling from library/hello-world
5b0f327be733: Pull complete
Digest: sha256:1f1404e9ea1a6665e3664626c5d2cda76cf90a4df50cfee16aab1a78f58a3f95
Status: Downloaded newer image for hello-world:latest
---> 05a3bd381fc2
Successfully built 05a3bd381fc2
Successfully tagged myusername/myimagename:1.0
WARNING: Image for service webapp was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating dockercompose_webapp_1 ...
Creating dockercompose_webapp_1 ... done
Attaching to dockercompose_webapp_1
webapp_1 |
webapp_1 | Hello from Docker!
webapp_1 | This message shows that your installation appears to be working correctly.
webapp_1 |
webapp_1 | To generate this message, Docker took the following steps:
webapp_1 | 1. The Docker client contacted the Docker daemon.
webapp_1 | 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
webapp_1 | 3. The Docker daemon created a new container from that image which runs the
webapp_1 | executable that produces the output you are currently reading.
webapp_1 | 4. The Docker daemon streamed that output to the Docker client, which sent it
webapp_1 | to your terminal.
webapp_1 |
webapp_1 | To try something more ambitious, you can run an Ubuntu container with:
webapp_1 | $ docker run -it ubuntu bash
webapp_1 |
webapp_1 | Share images, automate workflows, and more with a free Docker ID:
webapp_1 | https://cloud.docker.com/
webapp_1 |
webapp_1 | For more examples and ideas, visit:
webapp_1 | https://docs.docker.com/engine/userguide/
webapp_1 |
dockercompose_webapp_1 exited with code 0
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
da057afd3277 myusername/myimagename:1.0 "/hello" 3 minutes ago Exited (0) 3 minutes ago dockercompose_webapp_1
$ ls
Dockerfile docker-compose.yaml
あなたはdocker-compose up
両方がコンテナを構築し、がそれを始めた見ることができるように:docker-compose.yaml
はdocker-compose up
を実行すると、以下を生成することを考えると
version: '2'
services:
webapp:
build:
context: ./dir
image: username/repository:tag
。それに応じて名前も付けられます。したがって、と、その後docker-compose up
の両方を実行する必要はありません。docker-compose up
は、コンテナをビルドして開始するためです。コンテナが何らかの理由で再構築する必要がある場合最後に、あなたは単にコンテナを再構築するためにドッカーますdocker-compose up --force-recreate
を実行することができ、ビルドタグを追加して画像再作成します:docker-compose up --force-recreate --build
コンテナIDを設定することはできません。ドッカーのイメージタグを設定することは可能です。 タグは、イメージのバージョン管理だけです。ここに、タグ付きのイメージを作成するコマンドがあります。 $ docker build -t imagename:target-folder-pathタグ –
docker-composeを使用している場合は、ビルド時にイメージ名を指定してバージョン情報を指定することもできます。ビルドに追加のコマンドを実行する必要もなく、ビルドコマンドでdocker-composeファイルが構築されている場合は 'docker-compose up'でbuildを利用できます。 –