Docker Network

访问宿主机网络 host mode 使用host模式: docker run -d --network=host my-container:latest services: my-service: network_mode: host 添加hosts 使用--add-host选项添加映射到/etc/hosts文件,添加host.docker.internal到hosts docker run --rm -it --add-host host.docker.internal:host-gateway goexpect bash hosts in container root@00e0febe04e2:/app# cat /etc/hosts 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters 192.168.65.2 host.docker.internal 172.17.0.2 00e0febe04e2 访问宿主机网络 ssh root@host.docker.internal -p 2222

January 26, 2022 · 1 min · Peter

Docker Cheatsheet

docker cheatsheet docker # 不使用缓存重新build docker build . --no-cache # tag docker build -t peterchen0802/mypandoc:latest . docker tag peterchen0802/mypandoc:latest mypandoc:latest # 查看容器日志 docker logs SERVICE_NAME [-f] # 导出容器 # 注:用户既可以使用 docker load 来导入镜像存储文件到本地镜像库,也可以使用 docker import 来导入一个容器快照到本地镜像库。这两者的区别在于容器快照文件将丢弃所有的历史记录和元数据信息(即仅保存容器当时的快照状态),而镜像存储文件将保存完整记录,体积也要大。此外,从容器快照文件导入时可以重新指定标签等元数据信息。 docker export CONTAINER > TARFILENAME docker export CONTAINER -o TARFILENAME # 导入容器 docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]] docker import mypandoc.tar peterchen0802/mypandoc:latest # 指定导入的镜像名称 # -----清理 start----- ## 磁盘容量查看 docker system df ## 清理 docker rmi $(docker images --filter "dangling=true" -q) ## 清理无标签的镜像 docker image prune ## 清理磁盘,删除关闭的容器、无用的数据卷、网络,以及dangling镜像(无tag的镜像)。 docker system prune ## 更彻底的删除,将没有容器使用的镜像删除: docker system prune -a # -----清理 end----- docker-compose ...

December 6, 2021 · 1 min · Peter

Docker Private Registry

Docker Private Registry 简单使用,官方 官方提供的 https://hub.docker.com/_/registry Run a local registry: Quick Version $ docker run -d -p 5000:5000 --restart always --name registry registry:2 Now, use it from within Docker: $ docker pull ubuntu $ docker tag ubuntu localhost:5000/ubuntu $ docker push localhost:5000/ubuntu 更复杂的需求,harbor https://goharbor.io/ Our mission is to be the trusted cloud native repository for Kubernetes

July 22, 2020 · 1 min · Peter

PyCharm Docker

PyCharm 使用 Docker pycharm use docker for development and stage Development 使用windows和virtualbox,没有打开hyper-v所以无法使用docker,在虚拟机中使用docker并打开tcp,但是由于volume只能挂载宿主机,所以要先用pycharmm将文件拷贝到远程的映射目录,再使用。 此方法适合还没有准备开发环境和需要使用docker作为开发环境,但是windows本机没有docker的情况 我已使用虚拟机和pycharm远程同步功能达到同样的效果 在宿主机中开发时,可以很方便的将docker配置集成到configuration中 Stage PyCharm的docker也支持修改registry,如果有远程仓库需要的,也可以方便分发镜像

May 22, 2020 · 1 min · Peter

docker install

docker install install docker on Debian/Ubuntu link Uninstall old versions $ sudo apt-get remove docker docker-engine docker.io containerd runc Set up the repository $ sudo apt-get update $ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common $ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - or $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add - $ sudo apt-key fingerprint 0EBFCD88 $ sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/debian \ $(lsb_release -cs) \ stable" or sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ focal \ stable" or $ sudo add-apt-repository \ "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \ $(lsb_release -cs) \ stable" Install Docker Engine $ sudo apt-get update $ sudo apt-get install docker-ce docker-ce-cli containerd.io $ sudo docker run --rm hello-world $ sudo apt install docker-compose -y Without sudo to use docker $ sudo usermod -aG docker $USER $ sudo systemctl restart docker $ sudo systemctl enable docker Speed up https://YOURS.mirror.aliyuncs.com ...

April 20, 2020 · 1 min · Peter