Recent Comments
Category Archives: Docker
转载自https://note.qidong.name/2020/05/docker-proxy/ 有时因为网络原因,比如公司NAT,或其它啥的,需要使用代理。 Docker的代理配置,略显复杂,因为有三种场景。 但基本原理都是一致的,都是利用Linux的http_proxy等环境变量。 dockerd代理 在执行docker pull时,是由守护进程dockerd来执行。 因此,代理需要配在dockerd的环境中。 而这个环境,则是受systemd所管控,因此实际是systemd的配置。 sudo mkdir -p /etc/systemd/system/docker.service.d sudo touch /etc/systemd/system/docker.service.d/proxy.conf 在这个proxy.conf文件(可以是任意*.conf的形式)中,添加以下内容: [Service] Environment=”HTTP_PROXY=http://proxy.example.com:8080/” Environment=”HTTPS_PROXY=http://proxy.example.com:8080/” Environment=”NO_PROXY=localhost,127.0.0.1,.example.com” 其中,proxy.example.com:8080要换成可用的免密代理。 通常使用cntlm在本机自建免密代理,去对接公司的代理。 可参考《Linux下安装配置Cntlm代理》。 Container代理 在容器运行阶段,如果需要代理上网,则需要配置~/.docker/config.json。 以下配置,只在Docker 17.07及以上版本生效。 { “proxies”: { “default”: { “httpProxy”: “http://proxy.example.com:8080”, “httpsProxy”: “http://proxy.example.com:8080”, “noProxy”: “localhost,127.0.0.1,.example.com” } … Continue reading
停止、删除所有的docker容器和镜像
列出所有的容器 ID 1 docker ps -aq 停止所有的容器 1 docker stop $(docker ps -aq) 删除所有的容器 1 docker rm $(docker ps -aq) 删除所有的镜像 1 docker rmi $(docker images -q) 复制文件 1 docker cp mycontainer:/opt/file.txt /opt/local/ 2 docker cp /opt/local/file.txt mycontainer:/opt/ docker 1.13 … Continue reading
gitlab启用自带的docker registry
gitlab启用自带的docker registry gitlab安装后默认不开启自带的docker registry。 需要修改/etc/gitlab/gitlab.rb文件,修改以下配置 … registry_external_url ‘http://X.X.X.X:4567’ 注意,请不要使用5000端口,因为被gitlab所带的nginx默认占用了。配置前查一遍自己的端口占用情况 … 这里配置不带ssl证书认证的docker registry。修改后执行以下命令重启 sudo gitlab-ctl stop sudo gitlab-ctl reconfigure sudo gitlab-ctl start 安装后随便找个项目都能看到packages-container registry,还能看到各种提示信息,比如登录 docker login X.X.X.X:1234 这个内置的registry的用户名和密码账户与gitlab一致,可以和gitlab-runner 配合,在.gitlab-ci.yaml里使用 我们随便找个镜像nginx来演示推送过程 先把nginx拖下来 [root@gitlab-runner ~]# docker pull nginx Using default tag: latest latest: … Continue reading
HTTP/Insecure repository: http: server gave HTTP response to HTTPS client
docker push 报错 HTTP/Insecure repository 很简单,去daemon.json里面把 insecure-registries 加上 /etc/docker/daemon.json { “insecure-registries”: [“10.0.0.15:5000”] } 对于RHEL/CENTOS系列使用systemd的就按如上方法解决 包括自定义私有仓库也是相同的文件: { “insecure-registries”: [ “X.X.X.X:1234” ] } //有多个仓库就用逗号隔开 { “insecure-registries”: [ “X.X.X.X:1234”, “Y.Y.Y.Y:1234” ] }
感受docker build过程
这篇日志只是让你感受下制作镜像的过程,并不是详细介绍,后面有专门的文档来介绍制作镜像的各种办法。 docker build 命令用于使用 Dockerfile 创建镜像。 语法 docker build [OPTIONS] PATH | URL | – OPTIONS说明: –build-arg=[] :设置镜像创建时的变量; –cpu-shares :设置 cpu 使用权重; –cpu-period :限制 CPU CFS周期; –cpu-quota :限制 CPU CFS配额; –cpuset-cpus :指定使用的CPU id; –cpuset-mems :指定使用的内存 id; –disable-content-trust :忽略校验,默认开启; -f :指定要使用的Dockerfile路径; … Continue reading
docker基础镜像alpine
alpine是面向安全应用的轻量级linux发行版本,拖下来看一下 [root@localhost ~]# docker pull alpine Using default tag: latest latest: Pulling from library/alpine 921b31ab772b: Pull complete Digest: sha256:ca1c944a4f8486a153024d9965aafbe24f5723c1d5c02f4964c045a16d19dc54 Status: Downloaded newer image for alpine:latest [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE alpine latest 4d90542f0623 2 weeks … Continue reading
docker查看镜像信息
这里我们用inspect来查看镜像的详细信息: [root@localhost ~]# docker inspect ubuntu:14.04 [ { “Id”: “sha256:2c5e00d77a67934d5e39493477f262b878f127b9c01b491f06d8f06f78819578”, “RepoTags”: [ “ubuntu:14.04” ], “RepoDigests”: [ “ubuntu@sha256:2f7c79927b346e436cc14c92bd4e5bd778c3bd7037f35bc639ac1589a7acfa90” ], “Parent”: “”, “Comment”: “”, “Created”: “2019-05-15T21:21:13.96007615Z”, “Container”: “0da171ebca7c967d1bc6e8bb0bc12658c5b2c8cc242c9c86f503dae0684a5cc7”, “ContainerConfig”: { “Hostname”: “0da171ebca7c”, “Domainname”: “”, “User”: “”, “AttachStdin”: false, “AttachStdout”: false, “AttachStderr”: false, … Continue reading
docker启动示范”hello world”
这个镜像很好说明了docker启动的完整过程,注意看对应的输出日志 [root@localhost ~]# docker run –rm hello-world Unable to find image ‘hello-world:latest’ locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:41a65640635299bab090f783209c1e3a3f11934cf7756b09cb2f1e02147c6ed8 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be … Continue reading
docker diff/events命令
diff是用来比较容器和原镜像有什么区别,类似于git diff和status,这个直接用就行了,没太多好说的,比如刚才我们用docker cp复制了几份文件进入了ubuntu这个容器,看看有没有什么不同 [root@localhost ~]# docker diff ubuntu C /home A /home/rtest.txt A /home/rtest2.txt A /home/test.txt events是用来实时查看输出的,类似于tail -f ,所以你得重新打开个终端。比如,我们先start ubuntu_2,看看发生什么 [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES be9d5c6f2a25 ubuntu:14.04 “/bin/bash” 4 seconds ago Up … Continue reading
docker create/start 命令
docker 容器状态有一种是create,他的意思是创建了容器,但是还没启动,创建完成后,需要使用start来启动容器 我们可以试一下 先创建容器 [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7103a04f97d3 ubuntu:14.04 “/bin/bash” 3 hours ago Up 3 hours ubuntu [root@localhost ~]# docker images -a REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu 14.04 … Continue reading