40

I'm currently learning Docker, and have made a nice and simple Docker Compose setup. 3 containers, all with their own Dockerfile setup. How could I go about converting this to work on CoreOS so I can setup up a cluster later on?

web:
  build: ./app
  ports:
    - "3030:3000"
  links:
    - "redis"

newrelic:
  build: ./newrelic
  links:
    - "redis"

redis:
  build: ./redis
  ports:
    - "6379:6379"
  volumes:
    - /data/redis:/data
4

10 回答 10

51

取自https://docs.docker.com/compose/install/

唯一的问题是 /usr 是只读的,但 /opt/bin 是可写的并且在路径中,所以:

sd-xx~ # mkdir /opt/
sd-xx~ # mkdir /opt/bin
sd-xx~ # curl -L https://github.com/docker/compose/releases/download/1.3.3/docker-compose-`uname -s`-`uname -m` > /opt/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   403    0   403    0     0   1076      0 --:--:-- --:--:-- --:--:--  1080
100 7990k  100 7990k    0     0  2137k      0  0:00:03  0:00:03 --:--:-- 3176k
sd-xx~ # chmod +x /opt/bin/docker-compose

sd-xx~ # docker-compose
Define and run multi-container applications with Docker.

Usage:
  docker-compose [options] [COMMAND] [ARGS...]
  docker-compose -h|--help

Options:
  -f, --file FILE           Specify an alternate compose file (default: docker-compose.yml)
  -p, --project-name NAME   Specify an alternate project name (default: directory name)
  --verbose                 Show more output
  -v, --version             Print version and exit

Commands:
  build              Build or rebuild services
  help               Get help on a command
  kill               Kill containers
  logs               View output from containers
  port               Print the public port for a port binding
  ps                 List containers
  pull               Pulls service images
  restart            Restart services
  rm                 Remove stopped containers
  run                Run a one-off command
  scale              Set number of containers for a service
  start              Start services
  stop               Stop services
  up                 Create and start containers
  migrate-to-labels  Recreate containers to add labels
于 2015-07-27T20:19:51.373 回答
35

我创建了用于在 CoreOS 上安装最新 Docker Compose 的简单脚本: https ://gist.github.com/marszall87/ee7c5ea6f6da9f8968dd

#!/bin/bash
mkdir -p /opt/bin
curl -L `curl -s https://api.github.com/repos/docker/compose/releases/latest | jq -r '.assets[].browser_download_url | select(contains("Linux") and contains("x86_64"))'` > /opt/bin/docker-compose
chmod +x /opt/bin/docker-compose

只需运行它sudo

于 2015-09-25T13:21:38.827 回答
23

在 CoreOS 上安装或运行任何东西的正确方法是

  1. 将其作为一个单元安装
  2. 在单独的 docker 容器中运行

因为docker-compose您可能希望将它作为一个单元安装,就像您docker作为一个单元一样。请参阅 Digital Ocean 的 CoreOS 优秀指南和systemd 单元章节以了解更多信息。

根据您的云提供商或自定义安装找到您的云配置,请参阅https://coreos.com/os/docs/latest/cloud-config-locations.html了解位置。

通过将其添加为一个单元来安装 docker-compose

#cloud-config

coreos:
  units:
    - name: install-docker-compose.service
      command: start
      content: |
        [Unit]
        Description=Install docker-compose
        ConditionPathExists=!/opt/bin/docker-compose

        [Service]
        Type=oneshot
        RemainAfterExit=yes
        ExecStart=/usr/bin/mkdir -p /opt/bin/
        ExecStart=/usr/bin/curl -o /opt/bin/docker-compose -sL "https://github.com/docker/compose/releases/download/1.9.0/docker-compose-linux-x86_64"
        ExecStart=/usr/bin/chmod +x /opt/bin/docker-compose

请注意,我无法在 curl 语句中使用uname -sanduname -m扩展,因此我只是将它们替换为它们的扩展值。

验证您的配置文件

coreos-cloudinit -validate --from-file path-to-cloud-config

它应该输出类似

myhost core # coreos-cloudinit -validate --from-file path-to-cloudconfig
2016/12/12 12:45:03 Checking availability of "local-file"
2016/12/12 12:45:03 Fetching user-data from datasource of type "local-file"
myhost core #

请注意,coreos-cloudinit这不会验证您的云配置中的内容块。完成后重新启动 CoreOS,就可以开始了。

更新:正如@Wolfgang 评论,您可以运行coreos-cloudinit --from-file path-to-cloud-config而不是重新启动 CoreOS。

于 2016-12-12T12:48:00.183 回答
7

我还建议在 docker 容器中使用 docker-compose,例如来自dduportal的容器。

为了可用性,我扩展了我的 cloud-config.yml 如下:

write_files:
 - path: "/etc/profile.d/aliases.sh"
   content: |
     alias docker-compose="docker run -v \"\$(pwd)\":\"\$(pwd)\" -v /var/run/docker.sock:/var/run/docker.sock -e COMPOSE_PROJECT_NAME=\$(basename \"\$(pwd)\") -ti --rm --workdir=\"\$(pwd)\" dduportal/docker-compose:latest"

通过sudo coreos-cloudinit -from-url http-path-to/cloud-config.yml更新 cloud-config并重新启动系统后,您可以像在其他所有机器上一样使用 docker-compose 命令.

于 2016-08-18T14:19:56.307 回答
6

CentruyLabs 创建了一个名为fig2coreos的 ruby​​gem

它将 fig.yml 转换为 .service 文件

fig 自创建 docker-compose 以来已弃用,但语法似乎相同,因此它可能可以工作。

于 2015-04-02T13:28:56.767 回答
6

简单的3 个步骤

sudo mkdir -p /opt/bin

在官网https://docs.docker.com/compose/install/中获取命令并将输出路径从/usr/local/bin/docker-compose更改为/opt/bin

sudo curl -L "https://github.com/docker/compose/releases/download/1.9.0/docker-compose-$(uname -s)-$(uname -m)" -o /opt/bin/docker-compose

使可执行:

sudo chmod +x /opt/bin/docker-compose

现在你有了docker-compose :)

于 2016-11-30T13:07:19.837 回答
4

这是我找到的最好方法:

core@london-1 ~ $ docker pull dduportal/docker-compose
core@london-1 ~ $ cd /dir/where-it-is-your/docker-compose.yml
core@london-1 ~ $ docker run -v "$(pwd)":/app \
             -v /var/run/docker.sock:/var/run/docker.sock \
             -e COMPOSE_PROJECT_NAME=$(basename "$(pwd)")\
             -ti --rm \
             dduportal/docker-compose:latest up

完毕!

于 2015-07-26T16:55:36.450 回答
3

well, coreOS supports docker but it is bare bone linux with clustering suppport so you need to include a base image for all your containers ( use FROM and in Dockerfile you might also need to do RUN yum -y install bzip2 gnupg etc., ) that has the bins and libs that are needed by you app and redis ( better take some ubuntu base image )

Here you can put all of them in one container/docker or seperate if you do it seperate then you need to link the containers and optionally volume mount - docker has some good notes about it (https://docs.docker.com/userguide/dockervolumes/)

Atlast, you need to write cloud config which specifies the systemd units . In your case you will have 3 units that will be started by systemd ( systemd replaces the good old init system in coreOS) and feed it to coreos-cloudinit ( tip: coreos-cloudinit -from-file=./cloud-config -validate=false ), You also need to provide this cloud-config on the linux bootcmd for persistency.

于 2015-03-16T21:28:52.470 回答
1

目前,最简单的再次使用docker-composeCoreOS Vagrant VM的方法。您只需要确保转发 Docker 端口

如果你对使用不是特别执着docker-compose,可以试试运行Kubernetes 的CoreOS。有多种选择,我已经为 Azure 实现了其中一种

于 2015-03-17T11:26:07.770 回答
0

对于在 Fedora CoreOS 中使用 docker-compose,您可能会遇到 python 问题,但是从容器中运行 docker-compose 效果很好。

有一个方便的 bash 包装脚本,它记录在此处的官方文档中:https ://docs.docker.com/compose/install/#alternative-install-options在“作为容器安装”部分下。

于 2020-11-04T14:10:59.777 回答