sh CoreOS-Dokcer使用Docker加速器,安装Docker Compose

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh CoreOS-Dokcer使用Docker加速器,安装Docker Compose相关的知识,希望对你有一定的参考价值。

#!/bin/sh
# 如何使用Docker加速器
# 针对Docker客户端版本大于1.10的用户

# 您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器:
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://gpkywf9i.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

# Install Docker Compose as a container
sudo mkdir -p /opt/bin
# curl -L --fail https://github.com/docker/compose/releases/download/1.13.0/run.sh > /opt/bin/docker-compose
sudo tee /opt/bin/docker-compose <<-'EOF'
#!/bin/sh
#
# Run docker-compose in a container
#
# This script will attempt to mirror the host paths by using volumes for the
# following paths:
#   * $(pwd)
#   * $(dirname $COMPOSE_FILE) if it's set
#   * $HOME if it's set
#
# You can add additional volumes (or any docker run options) using
# the $COMPOSE_OPTIONS environment variable.
#


set -e

VERSION="1.13.0"
IMAGE="docker/compose:$VERSION"


# Setup options for connecting to docker host
if [ -z "$DOCKER_HOST" ]; then
    DOCKER_HOST="/var/run/docker.sock"
fi
if [ -S "$DOCKER_HOST" ]; then
    DOCKER_ADDR="-v $DOCKER_HOST:$DOCKER_HOST -e DOCKER_HOST"
else
    DOCKER_ADDR="-e DOCKER_HOST -e DOCKER_TLS_VERIFY -e DOCKER_CERT_PATH"
fi


# Setup volume mounts for compose config and context
if [ "$(pwd)" != '/' ]; then
    VOLUMES="-v $(pwd):$(pwd)"
fi
if [ -n "$COMPOSE_FILE" ]; then
    compose_dir=$(realpath $(dirname $COMPOSE_FILE))
fi
# TODO: also check --file argument
if [ -n "$compose_dir" ]; then
    VOLUMES="$VOLUMES -v $compose_dir:$compose_dir"
fi
if [ -n "$HOME" ]; then
    VOLUMES="$VOLUMES -v $HOME:$HOME -v $HOME:/root" # mount $HOME in /root to share docker.config
fi

# Only allocate tty if we detect one
if [ -t 1 ]; then
    DOCKER_RUN_OPTIONS="-t"
fi
if [ -t 0 ]; then
    DOCKER_RUN_OPTIONS="$DOCKER_RUN_OPTIONS -i"
fi

exec docker run --rm $DOCKER_RUN_OPTIONS $DOCKER_ADDR $COMPOSE_OPTIONS $VOLUMES -w "$(pwd)" $IMAGE "$@"
EOF

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

# docker-compose up -d (mysql)
cd "${0%/*}"
sudo mkdir -p mysql
sudo tee mysql/docker-compose.yml <<-'EOF'
version: '2'

services:
  mysql:
    image: mysql:5.6
    container_name: mysql-5.6
    restart: always
    ports:
      - 3306:3306
    volumes:
      - db_data:/var/lib/mysql
    environment:
      TZ: Asia/Shanghai
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: user
      MYSQL_USER: dev
      MYSQL_PASSWORD: dev
      MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
  db_data:
EOF

以上是关于sh CoreOS-Dokcer使用Docker加速器,安装Docker Compose的主要内容,如果未能解决你的问题,请参考以下文章

sh Docker htop:查看CPU,docker容器的内存使用情况

如何修复docker文件中的“sh:0:无法打开start.sh”?

使用 docker 文件运行脚本文件 (.sh) 时权限被拒绝

使用 Gitlab CI docker-in-docker 时如何修复 docker 容器中的“sh: tsc not found”错误

sh 使用Docker显示X11窗口

sh 使用Docker容器创建ElasticSearch转储