Skip to main content

Tổng hợp một số ví dụ về docker run container

MySQL

DIR=/data/mysql
mkdir -p /data/mysql/conf.d/
echo '
[mysqld]
character_set_server=utf8mb4
collation_server=utf8mb4_unicode_ci
' > /data/mysql/conf.d/my.cnf

mkdir -p /data/mysql/conf.d/datadir

docker 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

# OwnCloud
docker 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/jenkins
docker 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

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.dockerfile

FROM php:5-apache
RUN apt-get update
RUN apt-get install -y libcurl4-openssl-dev pkg-config libssl-dev  \
    && pecl install mongodb \
    && docker-php-ext-enable mongodb
RUN pecl install redis && docker-php-ext-enabl redis
docker build -t kienle/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/Saigon' > /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 kienle/php

Drone.io

mkdir /opt/apps/drone && cd /opt/apps/drone
mkdir data
# http://readme.drone.io/setup/settings/
echo '
REMOTE_DRIVER=gogs
REMOTE_CONFIG=https://gogs.hooli.com?open=false
DATABASE_DRIVER=mysql
DATABASE_CONFIG=root:pa55word@tcp(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 drone
docker rm drone
docker pull drone/drone
docker run ...

Go

docker exec -it jenkins bash
mkdir /var/jenkins_home/go/root
cd /var/jenkins_home/go/root
GOVERSION=1.7
wget 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.gz
tar -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 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

# Docker
docker run -it -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker wener/base:bash

# start dockerd
docker run -it --privileged -v /data/docker:/var/lib/docker --name dockerd --rm docker:dind

# DOCKER_HOST=tcp://docker:2375
docker 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"'
# mongo with mongoclient
docker run -d --restart always -v /etc/localtime:/etc/localtime:ro \
  --network service \
  -p 27017:27017 \
  -v $HOME/data/mongo:/data/db \
  --name mongo mongo
docker 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

Registry

# /certs  domain.crt  domain.key
mkdir auth
docker 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

# registry
docker run -d -p 5000:5000 -v `pwd`/data:/var/lib/registry --restart=always --name registry registry:2

Odoo

# Postgres
#  /var/lib/postgresql/data
docker 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/addons
data_dir = /var/lib/odoo
auto_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

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

Mời cà phê

Nếu cảm thấy blog mang đến những thông tin hữu ích cho công việc, cuộc sống, đam mê của bạn, đừng ngại ủng hộ một ly cà phê để mình có thêm động lực chia sẻ thêm nhiều kinh nghiệm, kiến thức nhé.

Bạn có thể ủng hộ mình qua:

Mời cà phê

Nếu cảm thấy blog mang đến những thông tin hữu ích cho công việc, cuộc sống, đam mê của bạn, đừng ngại ủng hộ một ly cà phê để mình có thêm động lực chia sẻ thêm nhiều kinh nghiệm, kiến thức nhé.

Bạn có thể ủng hộ mình qua:

Ví MoMo

image.png

Ví MoMo

Paypal

Hỗ trợ qua Paypal

Cám ơn mọi người!