ubuntu docker+docker registry全流程部署

#部署说明

  • 18.04安装 docker
1
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
  • 16.04 安装docker

    1
    sudo apt-get install docker.io
  • 安装 docker-compose
    从github上查询最新版本:https://github.com/docker/compose/releases

    1
    2
    3
    curl -L https://github.com/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

    chmod +x /usr/local/bin/docker-compose
  • 配置daemon.json

1
2
3
4
5
6
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://947o4dsx.mirror.aliyuncs.com"],
"insecure-registries":["127.0.0.1:5000"]
}

insecure-registries 忽略https
registry-mirrors 镜像加速器

  • 重启docker

    1
    2
    sudo systemctl daemon-reload
    sudo systemctl restart docker
  • 部署镜像仓库Registry

    1
    docker run -d -p 5000:5000 --restart=always --name registry \-v `pwd`/registry:/var/lib/registry \registry:2
  • DockerFile 示列

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    FROM java:8

    MAINTAINER [email protected]

    RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

    RUN mkdir -p /api

    WORKDIR /api

    EXPOSE 8888

    ADD api.jar ./app.jar


    CMD sleep 10;java -Xms128m -Xmx256m -Djava.security.egd=file:/dev/./urandom -jar app.jar
  • DockerCompose 示列

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    version: '2'

    services:
    #custom
    api:
    build:
    context: ./
    dockerfile: ./Dockerfile
    restart: always
    #networks:
    # - gate-tcp
    container_name: api
    image: 127.0.0.1:5000/api:latest
    ports:
    - "8888:8888"
    #networks:
    # gate-tcp:
    # driver: bridge
  • docker-compose 命令

    1
    2
    3
    docker stop api
    docker rm api
    docker-compose -f ./docker-compose.yml up -d --build api
  • docker-compose 错误

    1
    2
    3
    ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?

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

    将当前用户加入docker组可解决,如不行则 使用sudo运行docker-compose

    1
    sudo gpasswd -a ${USER} docker
  • 修改已有容器参数

    1
    docker container update --restart=always 容器名称