6
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

docker-composeで同じサービス名のサービスを複数起動する

Last updated at Posted at 2018-02-15

概要

ローカル環境をdocker-composeで管理していると、
同じサービス名を使いたくなることがあるが、
実は同じサービス名でもコンテナ名が競合していなければ問題ない。

バージョン

# OS
$ uname -a
Linux centos7 3.10.0-693.11.6.el7.x86_64 #1 SMP Thu Jan 4 01:06:37 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

# Docker
$ docker -v
Docker version 17.12.0-ce, build c97c6d6

# docker-compose
$ docker-compose -v
docker-compose version 1.18.0, build 8dd22a9

構成

$ tree ./
./
├── test1
│   └── docker-compose.yml
└── test2
    └── docker-compose.yml
test1/docker-compose.yml
version: '3'
services:
  test:
    container_name: test1
    image: busybox:latest
    command: tail -f /dev/null
test2/docker-compose.yml
version: '3'
services:
  test:
    container_name: test2
    image: busybox:latest
    command: tail -f /dev/null

実行

# test1起動
$ cd test1
test1 $ docker-compose up -d
Creating network "test1_default" with the default driver
Creating test1 ... done

# test2起動
test1 $ cd ../test2
test2 $ docker-compose up -d
Creating network "test2_default" with the default driver
Creating test2 ... done

# 確認
test2 $ docker ps
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS               NAMES
81469bf02855        busybox:latest      "tail -f /dev/null"   2 seconds ago       Up 1 second                             test2
615019dcbd0c        busybox:latest      "tail -f /dev/null"   9 seconds ago       Up 8 seconds                            test1
6
10
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
6
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?