Docker

查看内网地址

1
docker inspect --format='{{.NetworkSettings.IPAddress}}' $CONTAINER_ID

进入容器

1
docker exec -it name /bin/bash

Linux 安装

阿里云国内镜像

Centos

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
yum install docker
yum install docker-compose
service docker start

# 修改为国内镜像

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://xxxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

# 安装

docker pull mysql

# Run

docker run --name mysql --restart unless-stopped -p 3306:3306 -e MYSQL_ROOT_PASSWORD=910123 -d -v /mnt/mysql:/var/lib/mysql mysql
# Stop

docker stop mysql
# Start

docker start mysql

docker run --name elasticsearch --restart unless-stopped -p 9200:9200 -p 9300:9300 \
-v /mnt/elasticsearch/data:/usr/share/elasticsearch/data -e ES_JAVA_OPTS="-Xms128m -Xmx128m" \
-e "discovery.type=single-node" -d elasticsearch

docker run --name redis --restart unless-stopped -p 6379:6379 -v /mnt/redis/data:/data -d redis redis-server --appendonly yes

# jenkins

docker pull jenkins
chown -R 1000:1000 /mnt/jenkins/
docker run --restart unless-stopped -p 8080:8080 -p 50000:50000 --name jenkins -v /mnt/jenkins:/var/jenkins_home -d jenkins

# jenkins php
$ docker pull limingxinleo/jenkins-php-docker
$ useradd jenkins
$ chown -R jenkins:jenkins /mnt/jenkins/
$ docker run --restart unless-stopped -p 8080:8080 -p 50000:50000 --name jenkins \
-e "PATH=/home/jenkins/vendor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
-v "/mnt/jenkins:/var/jenkins_home" -d limingxinleo/jenkins-php-docker

docker-compose

报错解决

  1. Couldn’t connect to Docker daemon at http+docker://localunixsocket - is it running?
    1
    2
    3
    4
    5
    6
    7
    8
    $ sudo docker-compose up -d

    ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?

    If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

    # 解决:设置DOCKER_HOST,我的docker跑在sock上,所以按照如下设置
    export DOCKER_HOST=/var/run/docker.sock

配置docker-compose.yml

  1. Mysql

    1
    2
    3
    4
    5
    6
    7
    8
    mysql:
    image: mysql
    environment:
    MYSQL_ROOT_PASSWORD: 910123
    ports:
    - "3306:3306"
    volumes:
    - "/mnt/mysql:/var/lib/mysql"
  2. Redis

    1
    2
    3
    4
    5
    6
    redis:
    image: redis
    ports:
    - "6379:6379"
    volumes:
    - "/mnt/redis/data:/data"
  3. elasticsearch

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    elasticsearch:
    image: elasticsearch
    environment:
    ES_JAVA_OPTS: "-Xms128m -Xmx128m"
    discovery.type: "single-node"
    network.host: "0.0.0.0"
    ports:
    - "9200:9200"
    - "9300:9300"
    volumes:
    - "/mnt/elasticsearch/data:/usr/share/elasticsearch/data"
  4. kafka

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    zookeeper:
    image: wurstmeister/zookeeper
    ports:
    - "2181:2181"
    kafka:
    image: wurstmeister/kafka
    ports:
    - "9092:9092"
    links:
    - "zookeeper:zookeeper"
    environment:
    KAFKA_ADVERTISED_HOST_NAME: 127.0.0.1
    KAFKA_CREATE_TOPICS: "test:1:1"
    KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
  5. jenkins

    1
    2
    3
    4
    5
    6
    7
    8
    jenkins:
    image: jenkins
    restart: unless-stopped
    ports:
    - "8080:8080"
    - "50000:50000"
    volumes:
    - /Users/limx/runtime/jenkins:/var/jenkins_home

列出所有的容器 ID

1
docker ps -aq

停止所有的容器

1
docker stop $(docker ps -aq)

删除所有的容器

1
docker rm $(docker ps -aq)

删除所有的镜像

1
docker rmi $(docker images -q)