도커 컴포즈 yml 3 버전에서 2.1 로 변환하기
도커 컴포즈 실행하려고 했더니 버전 오류가 났다. 이상해서 버전 확인을 하니 라즈베리 파이의 도커 버전이 낮아서 최신 도커 yml 규격을 지원하지 않는 것. 그래서 이 문서를 작성한다.
도커 엔진 버전과 컴포즈 버전 확인
터미널에서 다음의 명령어로 도커 버전 확인
$ docker -v
Docker version 1.12.3, build 6b644ec
여기서는 1.12.3 이다.
컴포즈 파일 포맷 | 도커 엔진 릴리즈 | 해당여부 |
---|---|---|
3.3 | 17.06.0+ | |
3.2 | 17.04.0+ | |
3.1 | 1.13.1+ | |
3.0 | 1.13.0+ | |
2.2 | 1.13.0+ | |
2.1 | 1.12.0+ | 여기! |
2.0 | 1.10.0+ | |
1.0 | 1.9.1.+ |
그렇다면 이 상태에서 파일 포맷 3 파일을 실행하면 어떻게 될까?
$ docker-compose up
ERROR: Version in "./docker-compose.yml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a version of "2" (or "2.0") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/
지원되지 않는다고 나오며 버전 2 혹은 2.0 으로 명시해달라고 한다.
바꿔보기
바꿀 대상은 다음 저장소의 docker-compose.yml 파일이다.
https://github.com/scalafiddle/scalafiddle-io
바꾸기 전에 변경사항 확인
2.1 ~ 3.0 까지의 변경 사항을 알아보자. 즉, 처음부터 다 고치지 않고 변경사항만 되돌려줘서 편하게 작업해보자.
2.x 에서 3.x 로의 업그레이딩 문서는 여기에 있다.
Between versions 2.x and 3.x, the structure of the Compose file is the same, but several options have been removed:
volume_driver
: Instead of setting the volume driver on the service, define a volume using the top-level volumes option and specify the driver there.
version: "3" services: db: image: postgres volumes: - data:/var/lib/postgresql/data volumes: data: driver: mydriver
volumes_from
: To share a volume between services, define it using the top-level volumes option and reference it from each service that shares it using the service-level volumes option.
cpu_shares, cpu_quota, cpuset, mem_limit, memswap_limit
: These have been replaced by the resources key under deploy. Note that deploy configuration only takes effect when using docker stack deploy, and is ignored by docker-compose.
extends
: This option has been removed for version: “3.x” Compose files. (For more information, please see Extending services.)
group_add
: This option has been removed for version: “3.x” Compose files.
pids_limit
: This option has not been introduced in version: “3.x” Compose files.
link_local_ips
in networks: This option has not been introduced in version: “3.x” Compose files.
구조는 똑같다고 하고. volume_driver
, volumes_from
, cpu_shares
, cpu_quota
, cpuset
, mem_limit
, memswap_limit
,extends
,group_add
,pids_limit
,link_local_ips
가 제거됐다고 한다.
제거된 것만 나와있어서. 추가된 건 뭐있나 약간 위를 보니
Added: deploy
라고 나와있다.
즉 3 버전에서 2버전으로 그냥 바꿔도 작동하는데, deploy 라는 키워드만 어떻게 바꾸면 된다는 것이다.
바꿔보기
위에서 살펴 보았듯이 deploy 만 없으면 그냥 버전만 고치면 된다.
고쳐진 파일은 여기
고친 뒤에는 어떻게 될까?
$ docker-compose up
Creating network "scalafiddleio_default" with the default driver
Creating volume "scalafiddleio_sfdata" with default driver
Pulling editor (scalafiddle/scalafiddle-editor:latest)...
latest: Pulling from scalafiddle/scalafiddle-editor
10a267c67f42: Extracting [=====================================> ] 38.99 MB/52.58 MB
fb5937da9414: Download complete
9021b2326a1e: Download complete
8c6c40e9ec4f: Download complete
실행이 잘 된다.
글쓰기 민망할 정도로 쉽게 해결되었다.