• Dockergitlab


    1.国内拉取镜像比较慢,所以这里采用DaoCloud源

    curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://43049fd0.m.daocloud.io

    查看gitlab镜像有哪些版本

    docker search gitlab

    2.拉取镜像

    docker pull twang2218/gitlab-ce-zh

    查看镜像信息

    docker images

    3.启动容器

    docker run --detach \
      --hostname git.imebo.com \
      --publish 443:443 --publish 80:80 --publish 2222:22 \
      --name gitlab \
      --restart always \
      --volume /srv/gitlab/config:/etc/gitlab \
      --volume /srv/gitlab/logs:/var/log/gitlab \
      --volume /srv/gitlab/data:/var/opt/gitlab \
     gitlab/gitlab-ce:latest

    4.命令参数解释

    --hostname
    指定容器中绑定的域名,会在创建镜像仓库的时候使用到,这里绑定git.xiaohuruwei.com
     
    --publish
    端口映射,冒号前面是宿主机端口,后面是容器expose出的端口
     
    --volume
    volume 映射,冒号前面是宿主机的一个文件路径,后面是容器中的文件路径
    
    --detach
    后台运行

    成功运行镜像后,直接在浏览器打开宿主机IP访问,如:http://192.168.1.195。首次输入需要设置不少于8个字符的密码,用户名为: root .

    SSH问题:

    ssh方式访问

    因为是使用docker部署的,通过ssh方式(比如git clone git@git.xiaohuruwei.com)访问会有两层认证:

    一层是freelancer服务器的认证
    另一层是gitlab的认证。
    后者需要使用ssh-key
    前者可能需要ssh本身的反向代理(现在使用的nginx不支持除http,https以外的反向代理),

    现在发现使用端口转发的形式比较困难,但是可以改变默认的gitlab的ssh端口为非标准端口:
    直接修改gitlab配置文件中的变量:

    1
    gitlab_shell_ssh_port = 2222

    然后重新启动docker容器,就可以在web界面中看到相应的ssh地址发生了改变:
    ssh://git@git.imebo.com:2222/root/test.git 然后就直接可以继续使用git clone来继续操作了

    进入docker容器:

    docker exec -it e950a988d058 /bin/bash

    搜索镜像

    镜像可以去 https://hub.docker.com/ 搜索,或者使用命令

    如:

    user@ubuntu:~$ sudo docker search debian

    NAME

     DESCRIPTION

    STARS

    OFFICIAL

     AUTOMATED

    debian

     Debian is a Linux distribution that's comp...

    1519

    [OK]

    neurodebian

    NeuroDebian provides neuroscience research...

    25

    [OK]

    jesselang/debian-vagrant

     Stock Debian Images made Vagrant-friendly ...

     8

    [OK]

    armbuild/debian

     ARMHF port of debian

    8

    [OK]

    docker hub 几个镜像:

    nickistre/ubuntu-lamp

    https://hub.docker.com/r/nickistre/ubuntu-lamp/~/dockerfile/

    php

    https://hub.docker.com/_/php/

    mysql

    https://hub.docker.com/_/mysql/

    下载镜像

    sudo docker pull ubuntu

    显示本地镜像

    user@ubuntu:~$ sudo docker images

    REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

    ubuntu              latest              4ef6a5ece191        3 days ago          120.1 MB

    reinblau/lamp       latest              e9df29833f32        9 days ago          703.8 MB

    运行镜像,映射端口

    开启lamp镜像,映射主机8080端口到容器80端口

    e9d是 镜像id或镜像名

    user@ubuntu:~$ sudo docker run -it -p 8080:80 e9d apache2

    AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.1. Set the 'ServerName' directive globally to suppress this message

    user@ubuntu:~$ sudo docker run -it -p 8080:80 e9d /bin/bash

    root@ac4c74c9ac8a:/var/www/html# apache2

    AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message

    在后台运行,启动后容器内自动运行 /root/run.sh

    sudo docker run -itd -p 8080:80 e9d /root/run.sh

    参数:

    加上 -i -t 可以 ctrl+p ctrl+q 退出。

    -d, --detach=false         Run container in background and print container ID

    -i, --interactive=false    Keep STDIN open even if not attached

    -P, --publish-all=false    Publish all exposed ports to random ports

    -p, --publish=[]           Publish a container's port(s) to the host

    -t, --tty=false            Allocate a pseudo-TTY 分配一个伪TTY?

    依附到运行中的容器

    ac4c 是容器号

    sudo docker attach ac4c

    退出,一定不要用ctrl+c,那样就是让docker容器停止了。

    要用如下快捷键:先按,ctrl+p;再按,ctrl+q

    列出容器

    user@ubuntu:~$ sudo docker ps -a

    CONTAINER ID

    IMAGE

    COMMAND

    CREATED

    STATUS

    PORTS

    NAMES

    ac4c74c9ac8a

    e9d:latest

    "/bin/bash"

    7 minutes ago

    Up 7 minutes

    0.0.0.0:8080->80/tcp

    insane_mayer 

    3a4b37b41ea7

    e9d:latest

    "apache2"

    7 minutes ago

    Exited (0) 7 minutes ago 

    suspicious_darwin

    参数

    -a, --all=false       Show all containers (default shows just running)

    -q, --quiet=false     Only display numeric IDs

    查看端口映射

    ac4c是容器id

    user@ubuntu:~$ sudo docker port ac4c

    80/tcp -> 0.0.0.0:8080

    从dockerfile 创建镜像

    sudo docker build -t mylamp/test /home/user/Docker/mylamp_test/

    上例中,dockerfile存在于 /home/shen/Docker/mylamp_test/,镜像tag为mylamp/test

    参数

     -t, --tag=            Repository name (and optionally a tag) for the image

    删除镜像

    先删除所有依赖容器,再删除镜像。

    后面跟上标签或ID,跟标签会先删除标签(untag),如果没有标签指向镜像,就删除(delete)镜像。

    跟ID,删除所有相关标签(untag),再删除(delete)镜像。

    sudo docker rmi 2318

    sudo docker rmi ubuntu

    删除容器

    sudo docker rm e81

    批量操作容器

    停止正在运行的容器

    sudo docker stop $(sudo docker ps -q)

    删除(已经停止的,正在运行的不能删除)容器

    sudo docker rm $(sudo docker ps -a -q)



    文章出处:博客园http://www.cnblogs.com/go2bed/
    本文采用 知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议 进行许可,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
  • 相关阅读:
    一文弄懂Pytorch的DataLoader, DataSet, Sampler之间的关系
    常用Git命令大全
    职场被边缘化是怎样的
    HTTP网络设置
    java黑科技
    cmd执行java命令
    python 使用镜像下载依赖包
    初识go语言
    华为交换机(S5720)配置日志外发syslog服务器
    Neo4j记录
  • 原文地址:https://www.cnblogs.com/zhink/p/8608746.html
Copyright © 2020-2023  润新知