Skip to main content

Run container

常用选项#

# docker run--restart always# 调整容器中的时间-v /etc/localtime:/etc/localtime:ro# 后台运行-d

xhyve#

# 安装 https://github.com/zchee/docker-machine-driver-xhyve#installdocker-machine create --driver xhyve xhyveeval `docker-machine env xhyve`docker info

MySQL#

DIR=/data/mysql# 自定义配置mkdir -p /data/mysql/conf.d/echo '[mysqld]character_set_server=utf8mb4collation_server=utf8mb4_unicode_ci' > /data/mysql/conf.d/my.cnf
# 自定义数据目录mkdir -p /data/mysql/conf.d/datadir
# 使用自定义的配置启动 MySQLdocker run -d --restart always -v /etc/localtime:/etc/localtime:ro \  -p 3306:3306 \  -v /data/mysql/datadir:/var/lib/mysql -v /data/mysql/conf.d:/etc/mysql/conf.d \  -e MYSQL_ROOT_PASSWORD=ThisIsPassword \  --name mysql mysql

OwnCloud/Nextcloud#

# 需要先创建名为 mysql 的 mysql 容器,如果没有,可去除 --link# 启动 OwnClouddocker run -d --restart always -v /etc/localtime:/etc/localtime:ro \  -p 8080:80 \  -v /data/owncloud:/var/www/html \  --link mysql:mysql \  --name owncloud owncloud

反向代理#

sudo nano /data/owncloud/config/config.php

<?php/* $CONFIG */
$EXTRA_CONFIG = array (  "trusted_proxies"   => ['10.0.0.1'],  "overwritehost"     => "ssl-proxy.tld",  "overwriteprotocol" => "https",  "overwritewebroot"  => "/domain.tld/owncloud",  "overwritecondaddr" => "^10\.0\.0\.1$",);$CONFIG = array_merge($CONFIG, $EXTRA_CONFIG)

Jenkins#

# 不用映射, 备份通过 docker cp $ID:/var/jenkins_home# 设置 JENKINS_OPTS="--prefix=/jenkins" 来做反向代理# 如果目录有权限问题可手动设置 mkdir -p /data/jenkins && chwon 1000:1000 /data/jenkinsdocker run -d --restart always -v /etc/localtime:/etc/localtime:ro \  -p 8080:8080 -p 50000:50000 \  -v /data/jenkins:/var/jenkins_home \  --name jenkins jenkins

Jenkins 是离线的,由于 jenkins-ci.org 被墙,所以可能需要使用 HTTP 代理

gitea#

docker run -d --restart always -v /etc/localtime:/etc/localtime:ro \  -p 3000:3000 \  -v /data/gitea:/data \  --name gitea gitea/gitea

PHP#

官方提供了很多 PHP 版本, 如果需要额外的扩展建议自己 build 一个, 例如

php.dockerfile

FROM php:5-apacheRUN apt-get updateRUN apt-get install -y libcurl4-openssl-dev pkg-config libssl-dev  \    && pecl install mongodb \    && docker-php-ext-enable mongodbRUN pecl install redis && docker-php-ext-enabl redis
docker build -t wener/php -f php.dockerfile .docker run -d --restart always -p 80:80 -v /data/php/www:/var/www/html --name php wener/php# 也可以添加自己的配置# 设置默认时区echo 'date.timezone=Asia/Shanghai' > /data/php/config/php.ini;docker run -d --restart always  -p 80:80 -v /data/php/www:/var/www/html \  -v /data/php/config/php.ini:/usr/local/etc/php/php.ini  --name php wener/php

Drone.io#

# Drone 一般配合 Gogs 使用mkdir /opt/apps/drone && cd /opt/apps/drone# 用于存放数据mkdir data# 需要预先在 MySQL 中将 drone 库创建出来# 需要将数据库修改为具体的# 配置参考 http://readme.drone.io/setup/settings/echo 'REMOTE_DRIVER=gogsREMOTE_CONFIG=https://gogs.hooli.com?open=falseDATABASE_DRIVER=mysqlDATABASE_CONFIG=root:[email protected](localhost:3306)/drone?parseTime=true# HTTPS_PROXY=https://proxy.example.com# HTTP_PROXY=http://proxy.example.com# NO_PROXY=.example.com, *.docker.example.com' > dronerc
docker run -d --restart always -v /etc/localtime:/etc/localtime:ro \  -p=8080:8000 \    -v /opt/apps/drone/data:/var/lib/drone \    -v /var/run/docker.sock:/var/run/docker.sock \    --env-file ./dronerc \  --link mysql:mysql \    --name=drone drone/drone

更新#

docker stop dronedocker rm dronedocker pull drone/dronedocker run ...

安装 Go 环境#

# 进入容器执行docker exec -it jenkins bash# 安装 Go 环境mkdir /var/jenkins_home/go/rootcd /var/jenkins_home/go/rootGOVERSION=1.7wget https://storage.googleapis.com/golang/go$GOVERSION.linux-amd64.tar.gz# 或者使用代理下载# https_proxy=socks://127.0.0.1:8888 curl https://storage.googleapis.com/golang/go$GOVERSION.linux-amd64.tar.gz -o go$GOVERSION.linux-amd64.tar.gztar -C /var/jenkins_home/go/root -xzf go$GOVERSION.linux-amd64.tar.gz# 然后在 Jenkins 中添加环境变量# GOROOT=/var/jenkins_home/go/root/go# GOPATH=/var/jenkins_home/go

WatchTower#

# 将主机上的 docker 配置授权映射到容器内以便于拉取私有仓库# -i 检查间隔# --label-enable 监控带 com.centurylinklabs.watchtower.enable="true" 标记的docker run -d \  --name watchtower \  -v $HOME/.docker/config.json:/config.json \  -v /var/run/docker.sock:/var/run/docker.sock \  v2tec/watchtower container_to_watch --debug -i 120

Redis#

docker run -d --restart always -v /etc/localtime:/etc/localtime:ro \  -p 6379:6379 \  -v /data/redis:/data \  --name redis redis redis-server --appendonly yes
# 客户端docker run -it --link some-redis:redis --rm redis redis-cli -h redis -p 6379

Docker in Docker#

# 使用主机的 Dockerdocker run -it -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker wener/base:bash
# start dockerddocker run -it --privileged -v /data/docker:/var/lib/docker --name dockerd --rm docker:dind# 客户端# DOCKER_HOST=tcp://docker:2375docker run --rm -it --link dockerd:docker docker info

MongoDB#

docker run -d --restart always -v /etc/localtime:/etc/localtime:ro \  -p 27017:27017 \  -v /data/mongo:/data/db \  --name mongo mongo
# 客户端docker run -it --link some-mongo:mongo --rm mongo sh -c 'exec mongo "$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT/test"'
  • 由于 MongoDB 使用的 memmap, 通过 vbox 的映射不能够做共享数据卷, 但可以使用 xhyve 驱动的 docker-machine
# mongo with mongoclientdocker run -d --restart always -v /etc/localtime:/etc/localtime:ro \  --network service \  -p 27017:27017 \  -v $HOME/data/mongo:/data/db \  --name mongo mongodocker run -d --restart always -v /etc/localtime:/etc/localtime:ro \    --network service \    -e MONGO_URL=mongodb://mongo:27017 \    -p 3000:3000 \    --name mongoclient mongoclient/mongoclient

RethinkDB#

# 配置参考# https://github.com/rethinkdb/rethinkdb/blob/next/packaging/assets/config/default.conf.sampledocker run -d --restart always -v /etc/localtime:/etc/localtime:ro \  -p 8080:8080 -p 28015:28015 \  -v /data/rethinkdb:/data \  --name some-rethink rethinkdb
# 管理界面$BROWSER "http://$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' some-rethink):8080"
# 端口转发ssh -fNTL localhost:8080:$(ssh remote "docker inspect --format '{{ .NetworkSettings.IPAddress }}' some-rethink"):8080 remote# 在浏览器中打开xdg-open http://localhost:8080# 停止端口转发kill $(lsof -t -i @localhost:8080 -sTCP:listen)

Nexus#

# nexus3 支持 docker# 默认端口为 8081docker run -d --restart always -v /etc/localtime:/etc/localtime:ro \  -e NEXUS_CONTEXT=nexus \  -p8004:8004 -p8003:8003 -p8081:8081 \  -v /data/nexus:/nexus-data \  --name nexus sonatype/nexus3
# 默认账号密码 admin / admin123# 测试状态curl http://localhost:8081/nexus/service/local/status

Registry#

# 确保 /certs 中有 domain.crt 和 domain.key# 生成密码mkdir authdocker run --entrypoint htpasswd registry:2 -Bbn testuser testpassword > auth/htpasswd# 启动docker run -d -p 5000:5000 --restart=always --name registry \  -v `pwd`/auth:/auth \  -e "REGISTRY_AUTH=htpasswd" \  -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \  -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \  -v `pwd`/certs:/certs \  -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \  -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \  registry:2
# 启动一个简单的不安全的 registrydocker run -d -p 5000:5000 -v `pwd`/data:/var/lib/registry --restart=always --name registry registry:2

Odoo#

# Postgres# 数据目录 /var/lib/postgresql/datadocker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo --name odoo-db postgres
# Odoo# 配置文件 /etc/odoo/openerp-server.conf# 扩展路径 /mnt/extra-addons# docker run -p 8069:8069 --name odoo --link db:db -t odoo -- 自定义参数docker run -d -p 8069:8069 -v /data/odoo/addons:/mnt/extra-addons --name odoo --link odoo-db:db -t odoo

默认 openerp-server.conf

[options][options]addons_path = /mnt/extra-addons,/usr/lib/python2.7/dist-packages/openerp/addonsdata_dir = /var/lib/odooauto_reload = True; admin_passwd = admin; csv_internal_sep = ,; db_maxconn = 64; db_name = False; db_template = template1; dbfilter = .*; debug_mode = False; email_from = False; limit_memory_hard = 2684354560; limit_memory_soft = 2147483648; limit_request = 8192; limit_time_cpu = 60; limit_time_real = 120; list_db = True; log_db = False; log_handler = [':INFO']; log_level = info; logfile = None; longpolling_port = 8072; max_cron_threads = 2; osv_memory_age_limit = 1.0; osv_memory_count_limit = False; smtp_password = False; smtp_port = 25; smtp_server = localhost; smtp_ssl = False; smtp_user = False; workers = 0; xmlrpc = True; xmlrpc_interface =; xmlrpc_port = 8069; xmlrpcs = True; xmlrpcs_interface =; xmlrpcs_port = 8071

XAMPP#

  • tomsik68/xampp
  • mysql
    • /opt/lampp/var/mysql
  • phpadmin
    • /opt/lampp/phpmyadmin/config.inc.php
      • 配置数据库密码等
// 在网页上输入账号密码$cfg['Servers'][$i]['auth_type']    = 'cookie';$cfg['Servers'][$i]['AllowNoPassword']     = false;
docker run -d --restart always -v /etc/localtime:/etc/localtime:ro \  -p 22222:22 -p 80:80 -p 443:443 -d \  -v/data/xampp/www:/www \  --name xampp  tomsik68/xampp
# 重启 xampp/opt/lampp/lampp restart# 重启 apache/opt/lampp/bin/httpd -k restart

ldap#

docker run -d --restart always -v /etc/localtime:/etc/localtime:ro \  -p 10636:10636 -p 10389:10389 \  -v /data/apacheds:/opt/apacheds/instances \  --name apacheds wener/apacheds

Postgres#

docker run -d --restart always -v /etc/localtime:/etc/localtime:ro \    -p 5432:5432 -e POSTGRES_PASSWORD=thisispassword \    -v /data/pg:/var/lib/postgresql/data \    --name postgres postgres:alpine

其他服务#

cow#

curl https://github.com/cyfdecyf/cow/releases/download/0.9.8/cow-linux64-0.9.8.gz -Lo cow-linux64-0.9.8.gzgunzip cow-linux64-0.9.8.gzmkdir ~/binmv cow-* ~/bin/cowchmod +x ~/bin/cow
mkdir ~/.cowecho 'listen = http://127.0.0.1:7777proxy = socks5://127.0.0.1:8888' > ~/.cow/rc
cd ~/.cownohup cow &