Created
June 12, 2017 03:04
-
-
Save OneYX/432ad7c286a2a0ec10fadf68ab1f0252 to your computer and use it in GitHub Desktop.
CoreOS-Dokcer使用Docker加速器、安装Docker Compose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment